diff options
| author | Charles.Forsyth <devnull@localhost> | 2007-01-31 21:35:05 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2007-01-31 21:35:05 +0000 |
| commit | 313166a4d9889f8e2a542d19b2b9051eea4ee35b (patch) | |
| tree | 45b143402f8fc29327ba0327b46e432baac2185b /appl/lib/convcs/utf16_stob.b | |
| parent | ef16591df27afae3267b1ea5bfab68429be51dc6 (diff) | |
add utf16_btos/stob to convcs(2)
Diffstat (limited to 'appl/lib/convcs/utf16_stob.b')
| -rw-r--r-- | appl/lib/convcs/utf16_stob.b | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/appl/lib/convcs/utf16_stob.b b/appl/lib/convcs/utf16_stob.b new file mode 100644 index 00000000..312add88 --- /dev/null +++ b/appl/lib/convcs/utf16_stob.b @@ -0,0 +1,47 @@ +implement Stob; + +include "sys.m"; + sys: Sys; +include "convcs.m"; + +bigendian := 1; +header := 1; + +init(arg : string) : string +{ + sys = load Sys Sys->PATH; + case arg { + "le" => + bigendian = 0; + header = 0; + "be" => + header = 0; + } + return nil; +} + +stob(state : Convcs->State, s : string) : (Convcs->State, array of byte) +{ + if(state == nil){ + if(header) + s = sys->sprint("%c", 16rfeff) + s; + state = "doneheader"; + } + + b := array[len s * 2] of byte; + j := 0; + if(bigendian){ + for(i := 0; i < len s; i++){ + c := s[i]; + b[j++] = byte (c >> 8); + b[j++] = byte c; + } + }else{ + for(i := 0; i < len s; i++){ + c := s[i]; + b[j++] = byte c; + b[j++] = byte (c >> 8); + } + } + return (state, b); +} |
