Skip to content

Commit 61c2b84

Browse files
More robust regex and string handing for c_name() conversion for special and short names fixes #53
1 parent cef25bd commit 61c2b84

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

‎libEDSsharp/CanOpenNodeExporter.cs‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -921,25 +921,37 @@ string make_cname(string name)
921921
if (name == "")
922922
return "";
923923

924-
string[] bits = Regex.Split(name,@"[\W]+");
924+
Regex splitter = new Regex(@"[\W]+");
925925

926-
string output = "";
926+
//string[] bits = Regex.Split(name,@"[\W]+");
927+
var bits = splitter.Split(name).Where(s => s != String.Empty);
927928

928-
929+
string output = "";
929930

930931
char lastchar = ' ';
931932
foreach (string s in bits)
932933
{
933934
if(Char.IsUpper(lastchar) && Char.IsUpper(s.First()))
934935
output+="_";
935936

936-
output +=char.ToUpper(s[0]) + s.Substring(1);
937+
if (s.Length > 1)
938+
{
939+
output += char.ToUpper(s[0]) + s.Substring(1);
940+
}
941+
else
942+
{
943+
output += output.ToUpper();
944+
}
945+
946+
if(output.Length>0)
947+
lastchar = output.Last();
937948

938-
lastchar = output.Last();
939949
}
940950

941-
if(Char.IsLower(output[1]))
951+
if (output.Length > 1 && Char.IsLower(output[1]))
942952
output = Char.ToLower(output[0]) + output.Substring(1);
953+
else
954+
output = output.ToLower(); //single character
943955

944956
return output;
945957
}

0 commit comments

Comments
 (0)