Browse Source

[cs] Escape unsupported characters in -net-lib path

Cauê Waneck 10 years ago
parent
commit
81efef190b
1 changed files with 10 additions and 2 deletions
  1. 10 2
      gencs.ml

+ 10 - 2
gencs.ml

@@ -3143,7 +3143,15 @@ let add_cs = function
 	| "system" :: ns -> "cs" :: "system" :: ns
 	| "system" :: ns -> "cs" :: "system" :: ns
 	| ns -> ns
 	| ns -> ns
 
 
+let escape_chars =
+	String.replace_chars (fun chr ->
+		if (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') || chr = '_' then
+			Char.escaped chr
+		else
+			"_x" ^ (string_of_int (Char.code chr)) ^ "_")
+
 let netcl_to_hx cl =
 let netcl_to_hx cl =
+	let cl = escape_chars cl in
 	let cl = if String.length cl > 0 && String.get cl 0 >= 'a' && String.get cl 0 <= 'z' then
 	let cl = if String.length cl > 0 && String.get cl 0 >= 'a' && String.get cl 0 <= 'z' then
 			Char.escaped (Char.uppercase (String.get cl 0)) ^ (String.sub cl 1 (String.length cl - 1))
 			Char.escaped (Char.uppercase (String.get cl 0)) ^ (String.sub cl 1 (String.length cl - 1))
 		else
 		else
@@ -3158,11 +3166,11 @@ let netcl_to_hx cl =
 let netpath_to_hx std = function
 let netpath_to_hx std = function
 	| [],[], cl -> [], netcl_to_hx cl
 	| [],[], cl -> [], netcl_to_hx cl
 	| ns,[], cl ->
 	| ns,[], cl ->
-		let ns = (List.map String.lowercase ns) in
+		let ns = (List.map (fun s -> String.lowercase (escape_chars s)) ns) in
 		add_cs ns, netcl_to_hx cl
 		add_cs ns, netcl_to_hx cl
 	| ns,(nhd :: ntl as nested), cl ->
 	| ns,(nhd :: ntl as nested), cl ->
 		let nested = List.map (netcl_to_hx) nested in
 		let nested = List.map (netcl_to_hx) nested in
-		let ns = (List.map String.lowercase ns) @ [nhd] in
+		let ns = (List.map (fun s -> String.lowercase (escape_chars s)) ns) @ [nhd] in
 		add_cs ns, String.concat "_" nested ^ "_" ^ netcl_to_hx cl
 		add_cs ns, String.concat "_" nested ^ "_" ^ netcl_to_hx cl
 
 
 let lookup_ilclass std com ilpath =
 let lookup_ilclass std com ilpath =