Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nitely/nim-strunicode
Swift-like unicode string handling
https://github.com/nitely/nim-strunicode
grapheme-cluster nim nim-lang unicode
Last synced: 29 days ago
JSON representation
Swift-like unicode string handling
- Host: GitHub
- URL: https://github.com/nitely/nim-strunicode
- Owner: nitely
- License: mit
- Created: 2018-04-25T21:07:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-07T11:59:47.000Z (over 4 years ago)
- Last Synced: 2024-11-10T06:42:25.620Z (3 months ago)
- Topics: grapheme-cluster, nim, nim-lang, unicode
- Language: Nim
- Homepage: https://nitely.github.io/nim-strunicode/
- Size: 75.2 KB
- Stars: 24
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# strunicode
[![Build Status](https://img.shields.io/travis/nitely/nim-strunicode.svg?style=flat-square)](https://travis-ci.org/nitely/nim-strunicode)
[![licence](https://img.shields.io/github/license/nitely/nim-strunicode.svg?style=flat-square)](https://raw.githubusercontent.com/nitely/nim-strunicode/master/LICENSE)A library for unicode string handling,
inspired by the Swift language.## Install
```
nimble install strunicode
```## Compatibility
Nim +0.19.0
## Usage
```nim
import strunicode# both of these strings read as "CafΓ©"
# when printed, but have different
# unicode representation
const
cafeA = "Caf\u00E9".Unicode
cafeB = "Caf\u0065\u0301".Unicode# canonical comparison
# (note: none of this will copy)
assert cafeA == cafeB
assert cafeA == cafeB.string
assert cafeA == "Caf\u00E9"
assert cafeA == "Caf\u0065\u0301"
assert cafeA.string != cafeB.string# count characters
assert cafeA.count == cafeB.count# get character at position 3
assert cafeA.at(3) == cafeB.at(3)
assert cafeA.at(3) == "\u00E9"
assert cafeB.at(3) == "\u0065\u0301"assert cafeA.reversed == cafeB.reversed
assert cafeB.reversed == "\u0065\u0301faC"# iterate over characters
block:
var
expected = ["C", "a", "f", "\u0065\u0301"]
i = 0
for c in cafeB:
assert c == expected[i]
inc i# reverse characters
block:
var s = "π¦π·πΊπΎπ¨π±".Unicode
s.reverse
assert s == "π¨π±πΊπΎπ¦π·"# remove last character
block:
var s = "Caf\u0065\u0301"
s.setLen(s.len - s.Unicode.at(^1).len)
assert s == "Caf"# character/string interop with openArray[char]
block:
proc isDiacriticE(s: openArray[char]): bool =
# regular string comparison
s == "\u0065\u0301"assert cafeB.at(^1).toOpenArray.isDiacriticE
```
|
|
-> There's more, [read the docs](https://nitely.github.io/nim-strunicode/)## Tests
```
nimble test
```## LICENSE
MIT