FunSubStr.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using IwbZero.Expr;
  2. using IwbZero.ToolCommon.StringModel;
  3. namespace IwbZero.ExprFunctions.Functions
  4. {
  5. /// <summary>
  6. /// Sub字符串
  7. /// </summary>
  8. public class FunSubStr:IIwbFunction
  9. {
  10. public string Invoke(ExprObject exprObj)
  11. {
  12. string text = "";
  13. ExprObject child = exprObj.GetChild(0);
  14. if (child != null)
  15. {
  16. text = child.Expr;
  17. child = exprObj.GetChild(2);
  18. if (child != null)
  19. {
  20. int num = child.Expr.ValI();
  21. int num2 = text.Length;
  22. string text2 = "L";
  23. child = exprObj.GetChild(4);
  24. if (child != null)
  25. {
  26. num2 = child.Expr.ValI();
  27. if (num2 == 0)
  28. {
  29. var text3 = child.Expr.ToUpper();
  30. text2 = text3 == "R" ? "R" : "L";
  31. }
  32. }
  33. var child2 = exprObj.GetChild(6);
  34. if (child2 != null)
  35. {
  36. text2 = child2.Expr.ToUpper();
  37. }
  38. if (num < 0)
  39. {
  40. num = 0;
  41. }
  42. if (num < text.Length)
  43. {
  44. if (text2 == "R")
  45. {
  46. text = text.Substring(0, text.Length - num);
  47. if (child2 == null)
  48. {
  49. return text;
  50. }
  51. num = text.Length - num2;
  52. if (num < 0)
  53. {
  54. num = 0;
  55. }
  56. }
  57. if (num2 + num > text.Length)
  58. {
  59. num2 = text.Length - num;
  60. }
  61. text = text.Substring(num, num2);
  62. }
  63. else
  64. {
  65. text = "";
  66. }
  67. }
  68. }
  69. return text;
  70. }
  71. }
  72. }