Convert a string to camelCase, starting with a lowercase letter.
(s: &str)
| 491 | |
| 492 | /// Convert a string to camelCase, starting with a lowercase letter. |
| 493 | fn to_camel_case(s: &str) -> String { |
| 494 | if s.is_empty() { |
| 495 | return "variable".to_string(); |
| 496 | } |
| 497 | |
| 498 | // If it contains underscores, treat as snake_case |
| 499 | if s.contains('_') { |
| 500 | return snake_to_camel(s); |
| 501 | } |
| 502 | |
| 503 | // Just lowercase the first character |
| 504 | let mut chars = s.chars(); |
| 505 | let first = chars.next().unwrap(); |
| 506 | let mut result = first.to_lowercase().to_string(); |
| 507 | result.extend(chars); |
| 508 | result |
| 509 | } |
| 510 | |
| 511 | /// Convert `snake_case` to `camelCase`. |
| 512 | fn snake_to_camel(s: &str) -> String { |
no test coverage detected