Diff for /gforth/utf-8.fs between versions 1.3 and 1.6

version 1.3, 2004/12/12 22:20:00 version 1.6, 2004/12/28 17:27:24
Line 20 Line 20
   
 \ short: u8 means utf-8 encoded address  \ short: u8 means utf-8 encoded address
   
 : u8len ( u -- n )  : u8len ( u8 -- n )
     dup      $80 u< IF  drop 1  EXIT  THEN \ special case ASCII      dup      $80 u< IF  drop 1  EXIT  THEN \ special case ASCII
     $800  2 >r      $800  2 >r
     BEGIN  2dup u>=  WHILE  5 lshift r> 1+ >r  REPEAT      BEGIN  2dup u>=  WHILE  5 lshift r> 1+ >r  REPEAT
Line 79 Line 79
     restore-cursor >r 2dup swap type r> ;      restore-cursor >r 2dup swap type r> ;
   
 : <u8ins>  ( max span addr pos1 u8char -- max span addr pos2 )  : <u8ins>  ( max span addr pos1 u8char -- max span addr pos2 )
     >r >string over r@ u8len + swap move 2dup chars + r@ swap u8!+ drop      >r  2over r@ u8len + u< IF  rdrop bell  EXIT  THEN
       >string over r@ u8len + swap move 2dup chars + r@ swap u8!+ drop
     r> u8len >r  rot r@ chars + -rot r> chars + ;      r> u8len >r  rot r@ chars + -rot r> chars + ;
 : (u8ins)  ( max span addr pos1 u8char -- max span addr pos2 )  : (u8ins)  ( max span addr pos1 u8char -- max span addr pos2 )
     <u8ins> .all .rest ;      <u8ins> .all .rest ;
 : u8back  ( max span addr pos1 -- max span addr pos2 f )  : u8back  ( max span addr pos1 -- max span addr pos2 f )
     dup  IF  over + u8<< over -  0 max .all .rest      dup  IF  over + u8<< over -  0 max .all .rest
     ELSE  #bell emit  THEN 0 ;      ELSE  bell  THEN 0 ;
 : u8forw  ( max span addr pos1 -- max span addr pos2 f )  : u8forw  ( max span addr pos1 -- max span addr pos2 f )
     2 pick over <> IF  over + u8@+ u8emit over -  ELSE  #bell emit  THEN 0 ;      2 pick over <> IF  over + u8@+ u8emit over -  ELSE  bell  THEN 0 ;
 : (u8del)  ( max span addr pos1 -- max span addr pos2 )  : (u8del)  ( max span addr pos1 -- max span addr pos2 )
     over + dup u8<< tuck - >r over -      over + dup u8<< tuck - >r over -
     >string over r@ + -rot move      >string over r@ + -rot move
Line 97 Line 98
 : <u8del> ( max span addr pos1 -- max span addr pos2 0 )  : <u8del> ( max span addr pos1 -- max span addr pos2 0 )
   2 pick over <>    2 pick over <>
     IF  u8forw drop (u8del) .all 2 spaces .rest      IF  u8forw drop (u8del) .all 2 spaces .rest
     ELSE  #bell emit  THEN  0 ;      ELSE  bell  THEN  0 ;
 : u8eof  2 pick over or 0=  IF  bye  ELSE  <u8del>  THEN ;  : u8eof  2 pick over or 0=  IF  bye  ELSE  <u8del>  THEN ;
   
 : u8first-pos  ( max span addr pos1 -- max span addr 0 0 )  : u8first-pos  ( max span addr pos1 -- max span addr 0 0 )
Line 129 Line 130
 : u8tab-expand ( max span addr pos1 -- max span addr pos2 0 )  : u8tab-expand ( max span addr pos1 -- max span addr pos2 0 )
     key? IF  #tab (u8ins) 0  EXIT  THEN      key? IF  #tab (u8ins) 0  EXIT  THEN
     u8kill-expand 2dup extract-word dup 0= IF  nip EXIT  THEN      u8kill-expand 2dup extract-word dup 0= IF  nip EXIT  THEN
     search-prefix  tib-full?      search-prefix tib-full?
     IF    7 emit  2drop  0 0 prefix-found 2!      IF    7 emit  2drop  prefix-off
     ELSE  dup >r      ELSE  dup >r
         2>r >string r@ + 2r> 2swap insert          2>r >string r@ + 2r> 2swap insert
         r@ + rot r> + -rot          r@ + rot r> + -rot
     THEN      THEN
     prefix-found @ IF  bl (u8ins)  THEN  0 ;      prefix-found @ IF  bl (u8ins)  ELSE  .all .rest  THEN  0 ;
   
   : utf-8-io ( -- )
       ['] u8forw       ctrl F bindkey
       ['] u8back       ctrl B bindkey
       ['] ?u8del       ctrl H bindkey
       ['] u8eof        ctrl D bindkey
       ['] <u8del>      ctrl X bindkey
       ['] u8clear-tib  ctrl K bindkey
       ['] u8first-pos  ctrl A bindkey
       ['] u8end-pos    ctrl E bindkey
       ['] (u8enter)    #lf    bindkey
       ['] (u8enter)    #cr    bindkey
       ['] u8tab-expand #tab   bindkey
       ['] (u8ins)      IS insert-char
       ['] kill-prefix  IS everychar
       ['] save-cursor  IS everyline
       ['] u8key        IS key
       ['] u8emit       IS emit ;
   
 ' u8forw       ctrl F bindkey  
 ' u8back       ctrl B bindkey  
 ' ?u8del       ctrl H bindkey  
 ' u8eof        ctrl D bindkey  
 ' <u8del>      ctrl X bindkey  
 ' u8clear-tib  ctrl K bindkey  
 ' u8first-pos  ctrl A bindkey  
 ' u8end-pos    ctrl E bindkey  
 ' (u8enter)    #lf    bindkey  
 ' (u8enter)    #cr    bindkey  
 ' u8tab-expand #tab   bindkey  
 ' (u8ins) IS insert-char  
 ' save-cursor IS everyline  
 ' u8key IS key  
 ' u8emit IS emit  

Removed from v.1.3  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>