Return the first SQL keyword/word in `sql`, skipping leading whitespace, line comments, and block comments. Returns `None` if the input is empty or contains only whitespace/comments. The returned slice is a sub-slice of `sql` in its original case.
(sql: &str)
| 166 | /// |
| 167 | /// The returned slice is a sub-slice of `sql` in its original case. |
| 168 | pub fn first_sql_word(sql: &str) -> Option<&str> { |
| 169 | for seg in segments(sql) { |
| 170 | if let SqlSegment::Text(t) = seg { |
| 171 | let trimmed = t.trim_start(); |
| 172 | if trimmed.is_empty() { |
| 173 | continue; |
| 174 | } |
| 175 | let end = trimmed |
| 176 | .find(|c: char| c.is_ascii_whitespace() || c == '(' || c == ';') |
| 177 | .unwrap_or(trimmed.len()); |
| 178 | if end > 0 { |
| 179 | return Some(&trimmed[..end]); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | None |
| 184 | } |
| 185 | |
| 186 | /// Return the second SQL keyword/word in `sql`, skipping leading whitespace, |
| 187 | /// line comments, and block comments, then skipping the first word. Returns |