You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Utils.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection.Metadata.Ecma335;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Tensorflow.CodeGen
  8. {
  9. public static class Utils
  10. {
  11. public static string ConvertToUnderscore(string input)
  12. {
  13. if (string.IsNullOrEmpty(input))
  14. {
  15. return input;
  16. }
  17. StringBuilder result = new StringBuilder();
  18. int state = 0; // the previous char was not lowered.
  19. for (int i = 0; i < input.Length; i++)
  20. {
  21. char current = input[i];
  22. // 首字母不需要添加下划线
  23. if (i != 0 && char.IsUpper(current))
  24. {
  25. if(state == 0)
  26. {
  27. result.Append("_");
  28. state = 1;
  29. }
  30. result.Append(char.ToLower(current));
  31. }
  32. else
  33. {
  34. result.Append(char.ToLower(current));
  35. state = 0;
  36. }
  37. }
  38. return result.ToString();
  39. }
  40. }
  41. }