Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */
| 145 | |
| 146 | /* Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */ |
| 147 | int GetPyStringState(Accessor &styler, Sci_Position i, Sci_PositionU *nextIndex, literalsAllowed allowed) { |
| 148 | char ch = styler.SafeGetCharAt(i); |
| 149 | char chNext = styler.SafeGetCharAt(i + 1); |
| 150 | const int firstIsF = (ch == 'f' || ch == 'F'); |
| 151 | |
| 152 | // Advance beyond r, u, or ur prefix (or r, b, or br in Python 2.7+ and r, f, or fr in Python 3.6+), but bail if there are any unexpected chars |
| 153 | if (ch == 'r' || ch == 'R') { |
| 154 | i++; |
| 155 | ch = styler.SafeGetCharAt(i); |
| 156 | chNext = styler.SafeGetCharAt(i + 1); |
| 157 | } else if (IsPyStringTypeChar(ch, allowed)) { |
| 158 | if (chNext == 'r' || chNext == 'R') |
| 159 | i += 2; |
| 160 | else |
| 161 | i += 1; |
| 162 | ch = styler.SafeGetCharAt(i); |
| 163 | chNext = styler.SafeGetCharAt(i + 1); |
| 164 | } |
| 165 | |
| 166 | if (ch != '"' && ch != '\'') { |
| 167 | *nextIndex = i + 1; |
| 168 | return SCE_P_DEFAULT; |
| 169 | } |
| 170 | |
| 171 | if (ch == chNext && ch == styler.SafeGetCharAt(i + 2)) { |
| 172 | *nextIndex = i + 3; |
| 173 | |
| 174 | if (ch == '"') |
| 175 | return (firstIsF ? SCE_P_FTRIPLEDOUBLE : SCE_P_TRIPLEDOUBLE); |
| 176 | else |
| 177 | return (firstIsF ? SCE_P_FTRIPLE : SCE_P_TRIPLE); |
| 178 | } else { |
| 179 | *nextIndex = i + 1; |
| 180 | |
| 181 | if (ch == '"') |
| 182 | return (firstIsF ? SCE_P_FSTRING : SCE_P_STRING); |
| 183 | else |
| 184 | return (firstIsF ? SCE_P_FCHARACTER : SCE_P_CHARACTER); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | inline bool IsAWordChar(int ch, bool unicodeIdentifiers) { |
| 189 | if (ch < 0x80) |
no test coverage detected