swift - Compressing unicode strings -


i looking algorithm compress unicode strings in swift. strings compress relatively small (no more 160 characters).

i found lzw compression implemented here. copy pasted code worked ascii characters added unicode characters, got fatal error: unexpectedly found nil while unwrapping optional value while compressing, on line result.append(dict[w]!) guess algorithm doesn't support unicode characters since dict[c] undefined unicode character c.

how can tweak algorithm in order support unicode characters or should try other compression methods? if so, ones?

edit

by changing loop @ beginning from

for in 0 ..< 256 {     let s = string(unicodescalar(i))     dict[s] = } 

to

for in 0 ..< 0xffff {     let s = string(unicodescalar(i))     dict[s] = } 

i can algorithm work, although, solution requires calculation time , memory.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -