Exemple #1
0
 static u32string prefix()  {return u32string(U"kilo");}
Exemple #2
0
 static u32string prefix()  {return u32string(U"hecto");}
Exemple #3
0
 static u32string symbol() {return u32string(1, U'k');}
Exemple #4
0
 static u32string symbol() {return u32string(U"da");}
Exemple #5
0
 static u32string prefix()  {return u32string(U"deca");}
Exemple #6
0
 static u32string prefix()  {return u32string(U"milli");}
Exemple #7
0
 static u32string prefix()  {return u32string(U"centi");}
Exemple #8
0
 static u32string prefix()  {return u32string(U"micro");}
Exemple #9
0
 static u32string prefix()  {return u32string(U"nano");}
Exemple #10
0
 static u32string prefix()  {return u32string(U"pico");}
Exemple #11
0
 static u32string prefix()  {return u32string(U"femto");}
Exemple #12
0
std::pair<bool, u32string>
build_escaped_characters
(
  Iterator& current,
  const Iterator& end
)
{
  std::string building;
  bool error = false;
  int to_read = 0;

  while (*current == '\\' && error == false)
  {
    ++current;
    char32_t c = *current;
    switch(c)
    {
      case 'U':
      to_read = 8;
      ++current;
      break;

      case 'u':
      to_read = 4;
      ++current;
      break;

      case 'x':
      to_read = 2;
      ++current;
      break;

      case 'n':
      building += "\n";
      ++current;
      break;

      case 'r':
      building += "\r";
      ++current;
      break;

      case 't':
      building += "\t";
      ++current;
      break;

      case '\'':
      building += "\'";
      ++current;
      break;

      case '\"':
      building += "\"";
      ++current;
      break;

      case '\\':
      building += "\\";
      ++current;
      break;

      default:
      //invalid control character
      error = true;
      break;
    }

    //read the requested number of characters
    std::string chars;
    if (to_read > 0)
    {
      while (to_read > 0 && current != end && *current != '\'')
      {
        c = *current;  
        if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'))
        {
          chars += c;
        }
        else
        {
          break;
        }
        --to_read;
        ++current;
      }
    }

    //if we didn't read everything then error
    if (to_read != 0)
    {
      error = true;
    }
    else
    {
      uint32_t value = 0;
      for (char c : chars)
      {
        if (c >= '0' && c <= '9')
        {
          value = value * 16 + (c - '0');
        }
        else
        {
          value = value * 16 + (c - 'A' + 10);
        }
      }

      //it was a byte if it was two characters, otherwise it was a whole
      //character
      if (chars.length() == 2)
      {
        building += char(value & 0xFF);
      }
      else
      {
        building += utf32_to_utf8(u32string(1, value));
      }
    }
  }

  u32string u32result = utf8_to_utf32(building);
  return std::make_pair(!error, u32result);
}