Merge remote-tracking branch 'nim-lang/devel' into emscripten-support
This commit is contained in:
commit
7321fb0c18
9 changed files with 128 additions and 60 deletions
|
|
@ -18,6 +18,8 @@ import strutils
|
|||
##
|
||||
## Quick start example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## # Create a matrix which first rotates, then scales and at last translates
|
||||
##
|
||||
## var m:Matrix2d=rotate(DEG90) & scale(2.0) & move(100.0,200.0)
|
||||
|
|
@ -93,11 +95,11 @@ let
|
|||
IDMATRIX*:Matrix2d=matrix2d(1.0,0.0,0.0,1.0,0.0,0.0)
|
||||
## Quick access to an identity matrix
|
||||
ORIGO*:Point2d=point2d(0.0,0.0)
|
||||
## Quick acces to point (0,0)
|
||||
## Quick access to point (0,0)
|
||||
XAXIS*:Vector2d=vector2d(1.0,0.0)
|
||||
## Quick acces to an 2d x-axis unit vector
|
||||
## Quick access to an 2d x-axis unit vector
|
||||
YAXIS*:Vector2d=vector2d(0.0,1.0)
|
||||
## Quick acces to an 2d y-axis unit vector
|
||||
## Quick access to an 2d y-axis unit vector
|
||||
|
||||
|
||||
# ***************************************
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import times
|
|||
##
|
||||
## Quick start example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## # Create a matrix which first rotates, then scales and at last translates
|
||||
##
|
||||
## var m:Matrix3d=rotate(PI,vector3d(1,1,2.5)) & scale(2.0) & move(100.0,200.0,300.0)
|
||||
|
|
|
|||
|
|
@ -1319,15 +1319,44 @@ proc reversed*(s: string): string =
|
|||
|
||||
reverseUntil(len(s))
|
||||
|
||||
proc graphemeLen*(s: string; i: Natural): Natural =
|
||||
## The number of bytes belonging to 's[i]' including following combining
|
||||
## characters.
|
||||
var j = i.int
|
||||
var r, r2: Rune
|
||||
if j < s.len:
|
||||
fastRuneAt(s, j, r, true)
|
||||
result = j-i
|
||||
while j < s.len:
|
||||
fastRuneAt(s, j, r2, true)
|
||||
if not isCombining(r2): break
|
||||
result = j-i
|
||||
|
||||
proc lastRune*(s: string; last: int): (Rune, int) =
|
||||
## length of the last rune in 's[0..last]'. Returns the rune and its length
|
||||
## in bytes.
|
||||
if s[last] <= chr(127):
|
||||
result = (Rune(s[last]), 1)
|
||||
else:
|
||||
var L = 0
|
||||
while last-L >= 0 and ord(s[last-L]) shr 6 == 0b10: inc(L)
|
||||
inc(L)
|
||||
var r: Rune
|
||||
fastRuneAt(s, last-L, r, false)
|
||||
result = (r, L)
|
||||
|
||||
when isMainModule:
|
||||
let
|
||||
someString = "öÑ"
|
||||
someRunes = @[runeAt(someString, 0), runeAt(someString, 2)]
|
||||
compared = (someString == $someRunes)
|
||||
assert compared == true
|
||||
doAssert compared == true
|
||||
|
||||
assert reversed("Reverse this!") == "!siht esreveR"
|
||||
assert reversed("先秦兩漢") == "漢兩秦先"
|
||||
assert reversed("as⃝df̅") == "f̅ds⃝a"
|
||||
assert reversed("a⃞b⃞c⃞") == "c⃞b⃞a⃞"
|
||||
assert len(toRunes("as⃝df̅")) == runeLen("as⃝df̅")
|
||||
doAssert reversed("Reverse this!") == "!siht esreveR"
|
||||
doAssert reversed("先秦兩漢") == "漢兩秦先"
|
||||
doAssert reversed("as⃝df̅") == "f̅ds⃝a"
|
||||
doAssert reversed("a⃞b⃞c⃞") == "c⃞b⃞a⃞"
|
||||
doAssert len(toRunes("as⃝df̅")) == runeLen("as⃝df̅")
|
||||
const test = "as⃝"
|
||||
doAssert lastRune(test, test.len-1)[1] == 3
|
||||
doAssert graphemeLen("è", 0) == 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue