MCPcopy Create free account
hub / github.com/csyonghe/Spire / ParseOperators

Function ParseOperators

Source/CoreLib/Tokenizer.cpp:25–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 };
24
25 void ParseOperators(const String & str, List<Token> & tokens, TokenFlags& tokenFlags, int line, int col, int startPos, String fileName)
26 {
27 int pos = 0;
28 while (pos < str.Length())
29 {
30 wchar_t curChar = str[pos];
31 wchar_t nextChar = (pos < str.Length() - 1) ? str[pos + 1] : '\0';
32 wchar_t nextNextChar = (pos < str.Length() - 2) ? str[pos + 2] : '\0';
33 auto InsertToken = [&](TokenType type, const String & ct)
34 {
35 tokens.Add(Token(type, ct, line, col + pos, pos + startPos, fileName, tokenFlags));
36 tokenFlags = 0;
37 };
38 switch (curChar)
39 {
40 case '+':
41 if (nextChar == '+')
42 {
43 InsertToken(TokenType::OpInc, "++");
44 pos += 2;
45 }
46 else if (nextChar == '=')
47 {
48 InsertToken(TokenType::OpAddAssign, "+=");
49 pos += 2;
50 }
51 else
52 {
53 InsertToken(TokenType::OpAdd, "+");
54 pos++;
55 }
56 break;
57 case '-':
58 if (nextChar == '-')
59 {
60 InsertToken(TokenType::OpDec, "--");
61 pos += 2;
62 }
63 else if (nextChar == '=')
64 {
65 InsertToken(TokenType::OpSubAssign, "-=");
66 pos += 2;
67 }
68 else if (nextChar == '>')
69 {
70 InsertToken(TokenType::RightArrow, "->");
71 pos += 2;
72 }
73 else
74 {
75 InsertToken(TokenType::OpSub, "-");
76 pos++;
77 }
78 break;
79 case '*':
80 if (nextChar == '=')
81 {
82 InsertToken(TokenType::OpMulAssign, "*=");

Callers 1

TokenizeTextFunction · 0.85

Calls 3

TokenClass · 0.85
LengthMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected