Skip to content

Commit

Permalink
More robust regex and string handing for c_name() conversion for spec…
Browse files Browse the repository at this point in the history
…ial and short names fixes #53
  • Loading branch information
robincornelius committed Feb 3, 2017
1 parent cef25bd commit 61c2b84
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,25 +921,37 @@ string make_cname(string name)
if (name == "")
return "";

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

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


string output = "";

char lastchar = ' ';
foreach (string s in bits)
{
if(Char.IsUpper(lastchar) && Char.IsUpper(s.First()))
output+="_";

output +=char.ToUpper(s[0]) + s.Substring(1);
if (s.Length > 1)
{
output += char.ToUpper(s[0]) + s.Substring(1);
}
else
{
output += output.ToUpper();
}

if(output.Length>0)
lastchar = output.Last();

lastchar = output.Last();
}

if(Char.IsLower(output[1]))
if (output.Length > 1 && Char.IsLower(output[1]))
output = Char.ToLower(output[0]) + output.Substring(1);
else
output = output.ToLower(); //single character

return output;
}
Expand Down

0 comments on commit 61c2b84

Please sign in to comment.