8 karma · joined Oct 7, 2024 (2y ago) · 2 submissions
comment 2y ago · link · parent
/* Convert an escape sequence (pointed to by FROM) to its value on
the target, and to the execution character set. Do not scan past
LIMIT. Write the converted value into TBUF, if TBUF is non-NULL.
Returns an advanced pointer. Handles all relevant diagnostics.
If LOC_READER is non-NULL, then RANGES must be non-NULL: location
information is read from *LOC_READER, and *RANGES is updated
accordingly. */
static const uchar *
convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit,
struct _cpp_strbuf *tbuf, struct cset_converter cvt,
cpp_string_location_reader *loc_reader,
cpp_substring_ranges *ranges, bool uneval)
{
/\* Values of \a \b \e \f \n \r \t \v respectively. */
#if HOST_CHARSET == HOST_CHARSET_ASCII
static const uchar charconsts[] = { 7, 8, 27, 12, 10, 13, 9, 11 };
#elif HOST_CHARSET == HOST_CHARSET_EBCDIC
static const uchar charconsts[] = { 47, 22, 39, 12, 21, 13, 5, 11 };
#else
#error "unknown host character set"
#endif
uchar c;
/* Record the location of the backslash. */
source_range char_range;
if (loc_reader)
char_range = loc_reader->get_next ();
c = *from;
switch (c)
{
...
case 'n': c = charconsts[4]; break;
...comment 2y ago · link · parent
/// ProcessCharEscape - Parse a standard C escape sequence, which can occur in
/// either a character or a string literal.
static unsigned ProcessCharEscape(const char *ThisTokBegin,
const char *&ThisTokBuf,
const char *ThisTokEnd, bool &HadError,
FullSourceLoc Loc, unsigned CharWidth,
DiagnosticsEngine *Diags,
const LangOptions &Features) {
const char *EscapeBegin = ThisTokBuf;
// Skip the '\' char.
++ThisTokBuf;
// We know that this character can't be off the end of the buffer, because
// that would have been \", which would not have been the end of string.
unsigned ResultChar = *ThisTokBuf++;
switch (ResultChar) {
...
case 'n':
ResultChar = 10;
break;
...