=========================================================================== Known differences helpers =========================================================================== hasUTF8CodepointDifference returns true if this pattern+input combination has known differences due to coregex matching by
(pattern, input string)
| 149 | // This affects `.`, `\D`, `\W`, `\S`, negated character classes, and |
| 150 | // patterns that can match empty strings on multibyte input. |
| 151 | func hasUTF8CodepointDifference(pattern, input string) bool { |
| 152 | // Check if input contains multibyte UTF-8 characters |
| 153 | hasMultibyte := false |
| 154 | for _, r := range input { |
| 155 | if r >= 0x80 { |
| 156 | hasMultibyte = true |
| 157 | break |
| 158 | } |
| 159 | } |
| 160 | if !hasMultibyte { |
| 161 | return false |
| 162 | } |
| 163 | |
| 164 | // Patterns that match at byte level vs codepoint level |
| 165 | codepointPatterns := map[string]bool{ |
| 166 | `.`: true, // dot matches any codepoint in stdlib, any byte in coregex |
| 167 | `\D`: true, // non-digit |
| 168 | `\W`: true, // non-word |
| 169 | `\S`: true, // non-space |
| 170 | `[^a-z]`: true, // negated class |
| 171 | `[^0-9]`: true, // negated class |
| 172 | `[^a-zA-Z]`: true, |
| 173 | // Empty-match patterns step by codepoint in stdlib, by byte in coregex |
| 174 | ``: true, // empty pattern |
| 175 | `a*`: true, // can match empty |
| 176 | `a?`: true, // can match empty |
| 177 | `a*?`: true, // can match empty |
| 178 | `a??`: true, // can match empty |
| 179 | `.*`: true, // can match empty |
| 180 | `.*?`: true, // can match empty |
| 181 | `.?`: true, // can match empty |
| 182 | // Dot with captures also has codepoint differences |
| 183 | `(.)`: true, |
| 184 | `(.)+`: true, |
| 185 | `(.)*`: true, |
| 186 | `(.)?`: true, |
| 187 | `.+`: true, |
| 188 | } |
| 189 | return codepointPatterns[pattern] |
| 190 | } |
| 191 | |
| 192 | // isEmptyPatternCase returns true if this is an empty pattern case |
| 193 | // which has known differences in Split behavior. |
no outgoing calls
no test coverage detected