diff --git a/basis/unicode/breaks/breaks.factor b/basis/unicode/breaks/breaks.factor index df3b2f03e8..10bc235805 100644 --- a/basis/unicode/breaks/breaks.factor +++ b/basis/unicode/breaks/breaks.factor @@ -4,7 +4,8 @@ USING: combinators.short-circuit unicode.categories kernel math combinators splitting sequences math.parser io.files io assocs arrays namespaces make math.ranges unicode.normalize.private values io.encodings.ascii unicode.syntax unicode.data compiler.units fry -alien.syntax sets accessors interval-maps memoize locals words ; +alien.syntax sets accessors interval-maps memoize locals words +strings hints ; IN: unicode.breaks : first-grapheme ( str -- i ) unclip-slice grapheme-class over - [ grapheme-class tuck grapheme-break? ] find-index + [ grapheme-class tuck grapheme-break? ] find drop nip swap length or 1+ ; : last-grapheme ( str -- i ) unclip-last-slice grapheme-class swap - [ grapheme-class dup rot grapheme-break? ] find-last-index ?1+ nip ; + [ grapheme-class dup rot grapheme-break? ] find-last drop ?1+ nip ; -:: first-word ( str -- i ) - str unclip-slice word-break-prop over - [ swap str word-break-next ] assoc-find 2drop - nip swap length or 1+ ; +: first-word ( str -- i ) + [ unclip-slice word-break-prop over ] keep + '[ swap _ word-break-next ] assoc-find 2drop + nip swap length or 1+ ; inline + +HINTS: first-word string ; : >words ( str -- words ) [ first-word ] >pieces ; + +HINTS: >words string ; diff --git a/basis/unicode/normalize/normalize.factor b/basis/unicode/normalize/normalize.factor index f7aa248028..892379dc89 100644 --- a/basis/unicode/normalize/normalize.factor +++ b/basis/unicode/normalize/normalize.factor @@ -134,10 +134,10 @@ HINTS: string-append string string ; TUPLE: compose-state i str char after last-class ; : get-str ( state i -- ch ) - swap [ i>> + ] [ str>> ] bi ?nth ; -: current ( state -- ch ) 0 get-str ; -: to ( state -- state ) [ 1+ ] change-i ; -: push-after ( ch state -- state ) [ ?push ] change-after ; + swap [ i>> + ] [ str>> ] bi ?nth ; inline +: current ( state -- ch ) 0 get-str ; inline +: to ( state -- state ) [ 1+ ] change-i ; inline +: push-after ( ch state -- state ) [ ?push ] change-after ; inline :: try-compose ( state new-char current-class -- state ) state last-class>> current-class = @@ -147,13 +147,13 @@ TUPLE: compose-state i str char after last-class ; new-char state push-after current-class >>last-class ] if* - ] if ; + ] if ; inline DEFER: compose-iter : try-noncombining ( char state -- state ) tuck char>> swap combine-chars - [ >>char to f >>last-class compose-iter ] when* ; + [ >>char to f >>last-class compose-iter ] when* ; inline : compose-iter ( state -- state ) dup current [ @@ -164,7 +164,7 @@ DEFER: compose-iter [ drop ] [ swap try-noncombining ] if ] } [ try-compose to compose-iter ] } case - ] when* ; + ] when* ; inline recursive : compose-combining ( ch str i -- str i ) compose-state new @@ -172,7 +172,7 @@ DEFER: compose-iter swap >>str swap >>char compose-iter - { [ char>> , ] [ after>> % ] [ str>> ] [ i>> ] } cleave ; + { [ char>> , ] [ after>> % ] [ str>> ] [ i>> ] } cleave ; inline :: (compose) ( str i -- ) i str ?nth [ @@ -180,11 +180,13 @@ DEFER: compose-iter i 1+ str ?nth combining-class [ str i 1+ compose-combining ] [ , str i 1+ ] if ] if (compose) - ] when* ; + ] when* ; inline recursive : combine ( str -- comp ) [ pass-combining (compose) ] "" make ; +HINTS: combine string ; + PRIVATE> : nfc ( string -- nfc )