Skip to content

Commit

Permalink
uc, lc, ucfirst, lcfirst: UTF8String-->UTF8String versions.
Browse files Browse the repository at this point in the history
These may not be the most efficient implementations but it's
probably not bad.
  • Loading branch information
StefanKarpinski committed Jan 4, 2012
1 parent e949368 commit 7010db8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions j/utf8.j
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ strchr(s::UTF8String, c::Char) =
strcat(a::ByteString, b::ByteString, c::ByteString...) = UTF8String(memcat(a,b,c...))
# ^^ at least one must be UTF-8 or the ASCII-only method would get called

transform_to_utf8(s::String, f::Function) =
print_to_string(length(s), @thunk for c=s; print(f(c)); end)

uc(s::UTF8String) = transform_to_utf8(s,uc)
lc(s::UTF8String) = transform_to_utf8(s,lc)

ucfirst(s::UTF8String) = print_to_string(length(s), print, uc(s[1]), s[2:])
lcfirst(s::UTF8String) = print_to_string(length(s), print, lc(s[1]), s[2:])

## outputing UTF-8 strings ##

print(s::UTF8String) = print(s.data)
Expand Down

1 comment on commit 7010db8

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #99.

Please sign in to comment.