MCPcopy Create free account
hub / github.com/anjo76/angelscript / ProcessStringConstant

Method ProcessStringConstant

sdk/angelscript/source/as_compiler.cpp:11783–11974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11781}
11782
11783asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, bool processEscapeSequences)
11784{
11785 int charLiteral = -1;
11786
11787 // Process escape sequences
11788 asCArray<char> str((int)cstr.GetLength());
11789
11790 for( asUINT n = 0; n < cstr.GetLength(); n++ )
11791 {
11792#ifdef AS_DOUBLEBYTE_CHARSET
11793 // Double-byte charset is only allowed for ASCII and not UTF16 encoded strings
11794 if( (cstr[n] & 0x80) && engine->ep.scanner == 0 && engine->ep.stringEncoding != 1 )
11795 {
11796 // This is the lead character of a double byte character
11797 // include the trail character without checking it's value.
11798 str.PushLast(cstr[n]);
11799 n++;
11800 str.PushLast(cstr[n]);
11801 continue;
11802 }
11803#endif
11804
11805 asUINT val;
11806
11807 if( processEscapeSequences && cstr[n] == '\\' )
11808 {
11809 ++n;
11810 if( n == cstr.GetLength() )
11811 {
11812 if( charLiteral == -1 ) charLiteral = 0;
11813 return charLiteral;
11814 }
11815
11816 // Hexadecimal escape sequences will allow the construction of
11817 // invalid unicode sequences, but the string should also work as
11818 // a bytearray so we must support this. The code for working with
11819 // unicode text must be prepared to handle invalid unicode sequences
11820 if( cstr[n] == 'x' || cstr[n] == 'X' )
11821 {
11822 ++n;
11823 if( n == cstr.GetLength() ) break;
11824
11825 val = 0;
11826 int c = engine->ep.stringEncoding == 1 ? 4 : 2;
11827 for( ; c > 0 && n < cstr.GetLength(); c--, n++ )
11828 {
11829 if( cstr[n] >= '0' && cstr[n] <= '9' )
11830 val = val*16 + cstr[n] - '0';
11831 else if( cstr[n] >= 'a' && cstr[n] <= 'f' )
11832 val = val*16 + cstr[n] - 'a' + 10;
11833 else if( cstr[n] >= 'A' && cstr[n] <= 'F' )
11834 val = val*16 + cstr[n] - 'A' + 10;
11835 else
11836 break;
11837 }
11838
11839 // Rewind one, since the loop will increment it again
11840 n--;

Callers

nothing calls this directly

Calls 9

asStringDecodeUTF8Function · 0.85
asStringEncodeUTF8Function · 0.85
asStringEncodeUTF16Function · 0.85
PushLastMethod · 0.80
AssignMethod · 0.80
GetLengthMethod · 0.45
FormatMethod · 0.45
ConcatenateMethod · 0.45
AddressOfMethod · 0.45

Tested by

no test coverage detected