Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */
| 61 | |
| 62 | /* Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */ |
| 63 | static int GetPyStringState(Accessor &styler, int i, unsigned int *nextIndex, literalsAllowed allowed) { |
| 64 | char ch = styler.SafeGetCharAt(i); |
| 65 | char chNext = styler.SafeGetCharAt(i + 1); |
| 66 | |
| 67 | // Advance beyond r, u, or ur prefix (or r, b, or br in Python 3.0), but bail if there are any unexpected chars |
| 68 | if (ch == 'r' || ch == 'R') { |
| 69 | i++; |
| 70 | ch = styler.SafeGetCharAt(i); |
| 71 | chNext = styler.SafeGetCharAt(i + 1); |
| 72 | } else if (IsPyStringTypeChar(ch, allowed)) { |
| 73 | if (chNext == 'r' || chNext == 'R') |
| 74 | i += 2; |
| 75 | else |
| 76 | i += 1; |
| 77 | ch = styler.SafeGetCharAt(i); |
| 78 | chNext = styler.SafeGetCharAt(i + 1); |
| 79 | } |
| 80 | |
| 81 | if (ch != '"' && ch != '\'') { |
| 82 | *nextIndex = i + 1; |
| 83 | return SCE_P_DEFAULT; |
| 84 | } |
| 85 | |
| 86 | if (ch == chNext && ch == styler.SafeGetCharAt(i + 2)) { |
| 87 | *nextIndex = i + 3; |
| 88 | |
| 89 | if (ch == '"') |
| 90 | return SCE_P_TRIPLEDOUBLE; |
| 91 | else |
| 92 | return SCE_P_TRIPLE; |
| 93 | } else { |
| 94 | *nextIndex = i + 1; |
| 95 | |
| 96 | if (ch == '"') |
| 97 | return SCE_P_STRING; |
| 98 | else |
| 99 | return SCE_P_CHARACTER; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static inline bool IsAWordChar(int ch) { |
| 104 | return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_'); |
no test coverage detected