Skip to content

Commit

Permalink
Fix code where [Name.nbc] was expected to return -1 i case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Sagot committed Nov 13, 2019
1 parent 51d4a58 commit ba73a0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bin/distrib/ged2gwb/ged2gwb.camlp5.ml
Expand Up @@ -1126,7 +1126,7 @@ let capitalize_word s =
copy (i + 1) (Buff.store len c) (particle s (i + 1))
else
let nbc = Name.nbc s.[i] in
if nbc = 1 || nbc < 0 || i + nbc > String.length s then
if nbc = 1 || i + nbc > String.length s then
copy (i + 1) (Buff.store len s.[i]) true
else
let s = String.sub s i nbc in
Expand Down Expand Up @@ -1160,7 +1160,7 @@ let uppercase_word s =
copy (i + 1) (Buff.store len c) (particle s (i + 1))
else
let nbc = Name.nbc s.[i] in
if nbc = 1 || nbc < 0 || i + nbc > String.length s then
if nbc = 1 || i + nbc > String.length s then
copy (i + 1) (Buff.store len s.[i]) false
else
let s = String.sub s i nbc in
Expand Down
13 changes: 12 additions & 1 deletion bin/distrib/gwb2ged/gwb2ged.ml
Expand Up @@ -103,14 +103,25 @@ let find_br s ini_i =
@param i specifies the last char index (index to s -- one byte
char) *)
let rec display_note_aux oc tagn s len i =
(* FIXME: Rewrite this so we can get rid of this custom [nbc] *)
let nbc c =
if Char.code c < 0b10000000 then 1
else if Char.code c < 0b11000000 then -1
else if Char.code c < 0b11100000 then 2
else if Char.code c < 0b11110000 then 3
else if Char.code c < 0b11111000 then 4
else if Char.code c < 0b11111100 then 5
else if Char.code c < 0b11111110 then 6
else -1
in
let j = ref i in
(* read wide char (case charset UTF-8) or char (other charset) in s string*)
let rec output_onechar () =
if !j = String.length s then decr j
(* non wide char / UTF-8 char *)
else if !charset <> Utf8 then output_char oc s.[i]
(* 1 to 4 bytes UTF-8 wide char *)
else if i = !j || Name.nbc s.[!j] = -1 then begin
else if i = !j || nbc s.[!j] = -1 then begin
output_char oc s.[!j];
incr j;
output_onechar ()
Expand Down
2 changes: 1 addition & 1 deletion lib/util.ml
Expand Up @@ -122,7 +122,7 @@ let rec capitale_utf_8 s =
| _ -> s

let index_of_next_char s i =
min (String.length s) (i + max 1 (Name.nbc s.[i]))
min (String.length s) (i + Name.nbc s.[i])

let str_length s =
let len = String.length s in
Expand Down

0 comments on commit ba73a0c

Please sign in to comment.