Advertisement
Frumkin

Untitled

Aug 7th, 2021
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. std::string Parser::readCharacterLiteral(std::size_t& selection) {
  2.     std::string value = "";
  3.  
  4.     value += APOSTROPHE;
  5.     selection += 1;
  6.  
  7.     while (Code[selection] != APOSTROPHE) {
  8.         if (Code[selection] == BACKSLASH) {
  9.             value += BACKSLASH;
  10.             selection += 1;
  11.  
  12.             bool integerEscapeSequence = false;
  13.  
  14.             if (isdigit(Code[selection])) {
  15.                 value += Code[selection];
  16.                 selection += 1;
  17.  
  18.                 unsigned int iterations = 1;
  19.  
  20.                 while (isdigit(Code[selection]) && iterations <= 3) {
  21.                     value += Code[selection];
  22.                     selection += 1;
  23.                     iterations += 1;
  24.                 }
  25.  
  26.                 integerEscapeSequence = true;
  27.             }
  28.  
  29.             // if there is no integer escape sequence try to find a character escape sequence (example: '\e')
  30.             if (!integerEscapeSequence) {
  31.                 value += Code[selection];
  32.                 selection += 1;
  33.             }
  34.         } else {
  35.             value += Code[selection];
  36.             selection += 1;
  37.         }
  38.     }
  39.  
  40.     value += APOSTROPHE;
  41.     selection += 1;
  42.  
  43.     return value;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement