src/AwkHandler.h
branchv_0
changeset 24 c805c968b7ed
parent 23 bc20d499a458
child 25 13a1e1134797
equal deleted inserted replaced
23:bc20d499a458 24:c805c968b7ed
   143 		currentWriterMetadata.clear();
   143 		currentWriterMetadata.clear();
   144 		currentRelationConfiguration = nullptr;
   144 		currentRelationConfiguration = nullptr;
   145 	}
   145 	}
   146 
   146 
   147 	string_t a2v(const string_t& attributeName) {
   147 	string_t a2v(const string_t& attributeName) {
   148 		// FIXME: escape reserved names; prefix with _ ?
       
   149 		// cat awkgram.y | awk -v FS='\\{"|",' -v ORS='|' '/static const struct token tokentab/, /\};/ { if (/^\{/) { print $2} }'
   148 		// cat awkgram.y | awk -v FS='\\{"|",' -v ORS='|' '/static const struct token tokentab/, /\};/ { if (/^\{/) { print $2} }'
   150 		// BEGIN|BEGINFILE|END|ENDFILE|adump|and|asort|asorti|atan2|bindtextdomain|break|case|close|compl|continue|cos|dcgettext|dcngettext|default|delete|do|else|eval|exit|exp|fflush|for|func|function|gensub|getline|gsub|if|in|include|index|int|intdiv0|isarray|length|load|log|lshift|match|mktime|namespace|next|nextfile|or|patsplit|print|printf|rand|return|rshift|sin|split|sprintf|sqrt|srand|stopme|strftime|strtonum|sub|substr|switch|system|systime|tolower|toupper|typeof|while|xor
   149 		std::wregex awkReservedNames(L"BEGIN|BEGINFILE|END|ENDFILE|adump|and|asort|asorti|atan2|bindtextdomain|break|case|close|compl|continue|cos|dcgettext|dcngettext|default|delete|do|else|eval|exit|exp|fflush|for|func|function|gensub|getline|gsub|if|in|include|index|int|intdiv0|isarray|length|load|log|lshift|match|mktime|namespace|next|nextfile|or|patsplit|print|printf|rand|return|rshift|sin|split|sprintf|sqrt|srand|stopme|strftime|strtonum|sub|substr|switch|system|systime|tolower|toupper|typeof|while|xor");
   151 		return attributeName;
   150 		std::wregex trReservedNames(L"_escape|_unescape|_readVariables|_writeVariables|record");
       
   151 		if (regex_match(attributeName, awkReservedNames) || regex_match(attributeName, trReservedNames)) return a2v(L"_" + attributeName);
       
   152 		else return attributeName;
   152 	}
   153 	}
   153 
   154 
   154 	string_t escapeAwkValue(const string_t& value) {
   155 	string_t escapeAwkValue(const string_t& value) {
   155 		std::wstringstream escaped;
   156 		std::wstringstream escaped;
   156 		for (wchar_t ch : value) {
   157 		for (wchar_t ch : value) {