| Crates.io | gstring |
| lib.rs | gstring |
| version | 0.13.2 |
| created_at | 2024-12-03 16:20:01.178768+00 |
| updated_at | 2025-11-14 01:30:35.264456+00 |
| description | String with support for Unicode graphemes |
| homepage | |
| repository | https://github.com/qtfkwk/gstring |
| max_upload_size | |
| id | 1470248 |
| size | 47,543 |
String with support for Unicode graphemes
use gstring::*;
const S: &str = "a\u{310}e\u{301}o\u{308}\u{332}";
// Create a GString
let mut s = GString::from(S);
assert_eq!(s, S);
assert_eq!(s.graphemes(), &["a\u{310}", "e\u{301}", "o\u{308}\u{332}"]);
assert_eq!(s.len(), 3);
assert!(!s.is_empty());
assert_eq!(s.chars(), &['a', '\u{310}', 'e', '\u{301}', 'o', '\u{308}', '\u{332}']);
assert_eq!(s.bytes(), &[0x61, 0xcc, 0x90, 0x65, 0xcc, 0x81, 0x6f, 0xcc, 0x88, 0xcc, 0xb2]);
// Insert a &str
s.insert(0, "i\u{301}u\u{301}");
assert_eq!(s, "i\u{301}u\u{301}a\u{310}e\u{301}o\u{308}\u{332}");
// Remove a grapheme at an index
assert_eq!(s.remove(1), "u\u{301}");
assert_eq!(s, "i\u{301}a\u{310}e\u{301}o\u{308}\u{332}");
// Push a &str
s.push("i\u{301}u\u{301}");
assert_eq!(s, "i\u{301}a\u{310}e\u{301}o\u{308}\u{332}i\u{301}u\u{301}");
// Pop last grapheme
assert_eq!(s.pop().unwrap(), "u\u{301}");
assert_eq!(s, "i\u{301}a\u{310}e\u{301}o\u{308}\u{332}i\u{301}");
// Slice
assert_eq!(s.slice(1..4), "a\u{310}e\u{301}o\u{308}\u{332}");
// Splice
assert_eq!(s.splice(1..4, ""), "a\u{310}e\u{301}o\u{308}\u{332}");
assert_eq!(s, "i\u{301}i\u{301}");
// Drain
assert_eq!(s.drain(..), "i\u{301}i\u{301}");
assert_eq!(s, "");