// Transform strings (or substrings) prefixed with introducer (_charset) to ASCII equivalent. void Parser::transformString(const char* start, unsigned length, string& dest) { const static char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; const unsigned fromBegin = start - lex.start; HalfStaticArray<char, 256> buffer; const char* pos = start; // We need only the "introduced" strings, in the bounds of "start" and "length" and in "pos" // order. Let collect them. SortedArray<StrMark> introducedMarks; GenericMap<NonPooled<IntlString*, StrMark> >::ConstAccessor accessor(&strMarks); for (bool found = accessor.getFirst(); found; found = accessor.getNext()) { const StrMark& mark = accessor.current()->second; if (mark.introduced && mark.pos >= fromBegin && mark.pos < fromBegin + length) introducedMarks.add(mark); } for (size_t i = 0; i < introducedMarks.getCount(); ++i) { const StrMark& mark = introducedMarks[i]; const char* s = lex.start + mark.pos; buffer.add(pos, s - pos); if (!isspace(UCHAR(pos[s - pos - 1]))) buffer.add(' '); // fix _charset'' becoming invalid syntax _charsetX'' const size_t count = buffer.getCount(); const size_t newSize = count + 2 + mark.str->getString().length() * 2 + 1; buffer.grow(newSize); char* p = buffer.begin() + count; *p++ = 'X'; *p++ = '\''; const char* s2 = mark.str->getString().c_str(); for (const char* end = s2 + mark.str->getString().length(); s2 < end; ++s2) { *p++ = HEX_DIGITS[UCHAR(*s2) >> 4]; *p++ = HEX_DIGITS[UCHAR(*s2) & 0xF]; } *p = '\''; fb_assert(p < buffer.begin() + newSize); pos = s + mark.length; } fb_assert(start + length - pos >= 0); buffer.add(pos, start + length - pos); dest.assign(buffer.begin(), MIN(string::max_length(), buffer.getCount())); }
void IntlUtil::toUpper(Jrd::CharSet* cs, string& s) { HalfStaticArray<UCHAR, BUFFER_SMALL> buffer; FB_SIZE_T len = s.length(); ULONG count = toUpper(cs, len, (const UCHAR*) s.c_str(), len * 4, buffer.getBuffer(len * 4), NULL); if (count != INTL_BAD_STR_LENGTH) s.assign(buffer.begin(), count); else fb_assert(false); }