Skip to content
Permalink
Browse files

Fix code where [Name.nbc] was expected to return -1 i case of error

  • Loading branch information...
sagotch committed Nov 13, 2019
1 parent 51d4a58 commit ba73a0cc8311d9a56da7a631c1660c99f31915d8
Showing with 15 additions and 4 deletions.
  1. +2 −2 bin/distrib/ged2gwb/ged2gwb.camlp5.ml
  2. +12 −1 bin/distrib/gwb2ged/gwb2ged.ml
  3. +1 −1 lib/util.ml
@@ -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
@@ -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
@@ -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 ()
@@ -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

0 comments on commit ba73a0c

Please sign in to comment.
You can’t perform that action at this time.