Skip to main content
typo fix
Source Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101

TenaryTernary expressions

Tenary expressions

Ternary expressions

deleted 25 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177

Now we should have a look at the ParserHelper classYou could also turn this into extension methods. On thing I notice is

Now we should have a look at the ParserHelper class. On thing I notice is

You could also turn this into extension methods.

added 1493 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177

ParserHelper

Setting aside what already been said about the tenary method.

  • the decimal separator differs from country to country. Using of the CultureInfo is recommended.

  • redunant else to be removed. If the condition is true, the else part is never reached and can therfor be removed.

      if(condition) return true;
      else return (true or false);
    

These and the above implemented the class looks like

public static class ParserHelper
{
    public static bool IsNameChar(char a)
    {
        return a == '_' || char.IsLetter(a);
    }
    private static char decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];
    public static bool IsNum(char a)
    {
        return  (a == decimalSeparator) || char.IsDigit(a);
    }

    public static bool IsLeftBracket(char a)
    {
        return (a == '(');
    }

    public static bool IsRightBracket(char a)
    {
        return (a == ')');
    }

    public static bool IsOperator(char a)
    {
        return "+-*/%=".Contains(a);
    }

    public static bool IsSeparator(char a)
    {
        return (a == ';');
    }

    public static bool IsWhiteSpace(char a)
    {
        return char.IsWhiteSpace(a);
    }
}

Now we should have a look at the ParserHelper class. On thing I notice is

ParserHelper

Setting aside what already been said about the tenary method.

  • the decimal separator differs from country to country. Using of the CultureInfo is recommended.

  • redunant else to be removed. If the condition is true, the else part is never reached and can therfor be removed.

      if(condition) return true;
      else return (true or false);
    

These and the above implemented the class looks like

public static class ParserHelper
{
    public static bool IsNameChar(char a)
    {
        return a == '_' || char.IsLetter(a);
    }
    private static char decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];
    public static bool IsNum(char a)
    {
        return  (a == decimalSeparator) || char.IsDigit(a);
    }

    public static bool IsLeftBracket(char a)
    {
        return (a == '(');
    }

    public static bool IsRightBracket(char a)
    {
        return (a == ')');
    }

    public static bool IsOperator(char a)
    {
        return "+-*/%=".Contains(a);
    }

    public static bool IsSeparator(char a)
    {
        return (a == ';');
    }

    public static bool IsWhiteSpace(char a)
    {
        return char.IsWhiteSpace(a);
    }
}

Now we should have a look at the ParserHelper class. On thing I notice is

added 732 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
deleted 78 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
deleted 68 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
added 3141 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
added 621 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
deleted 47 characters in body
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading
Source Link
Heslacher
  • 50.9k
  • 5
  • 83
  • 177
Loading