Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get with unicode strings
Dear Gintaras,

I understand that "get" does not work with unicode strings. Therefore, I implemented the following code to do it :
Member function str.getU
Copy      Help
function~ str'sinp int'from int'nc
;Unicode versdion of "get" macro, it also serves left
str s=sinp
s.unicode ;;convert to UTF-16
str s1.get(s 2*from 2*nc)

I wonder whether you have any relevant comments. Regards, Thanks.
Some changes.
Member function str.getU2
Copy      Help
function$ $sinp from nc

;Unicode versdion of "get" macro, it also serves left

;Error if from invalid.
;If nc < 0 or too big, gets all right part.

str s.unicode(sinp) ;;convert to UTF-16
from*2; nc*2
if(from<0 or from>s.len) end ERR_BADARG
if(nc<0 or from+nc>s.len) nc=s.len-from
this.ansi(s+from -1 nc/2)
ret this
Many thanks. I think that nc should not be doubled in this version.
Regards, Simos.
Yes, added /2

Forum Jump:

Users browsing this thread: 1 Guest(s)