Skip to content

Instantly share code, notes, and snippets.

@MichalBrylka
Created April 23, 2019 19:26
Show Gist options
  • Save MichalBrylka/1161760a854bb59cff5508a95d4edc6e to your computer and use it in GitHub Desktop.
Save MichalBrylka/1161760a854bb59cff5508a95d4edc6e to your computer and use it in GitHub Desktop.
private static byte ParseDaysOfWeek(ReadOnlySpan<char> text)
{
if (text.Length == 4 && char.ToUpper(text[0]) == 'N' && char.ToUpper(text[1]) == 'O' &&
char.ToUpper(text[2]) == 'N' && char.ToUpper(text[3]) == 'E'
)
return 0;
else if (text.Length == 6 && char.ToUpper(text[0]) == 'M' && char.ToUpper(text[1]) == 'O' &&
char.ToUpper(text[2]) == 'N' && char.ToUpper(text[3]) == 'D' && char.ToUpper(text[4]) == 'A' &&
char.ToUpper(text[5]) == 'Y'
)
return 1;
else if (text.Length == 7 && char.ToUpper(text[0]) == 'T' && char.ToUpper(text[1]) == 'U' &&
char.ToUpper(text[2]) == 'E' && char.ToUpper(text[3]) == 'S' && char.ToUpper(text[4]) == 'D' &&
char.ToUpper(text[5]) == 'A' && char.ToUpper(text[6]) == 'Y'
)
return 2;
else if (text.Length == 9 && char.ToUpper(text[0]) == 'W' && char.ToUpper(text[1]) == 'E' &&
char.ToUpper(text[2]) == 'D' && char.ToUpper(text[3]) == 'N' && char.ToUpper(text[4]) == 'E' &&
char.ToUpper(text[5]) == 'S' && char.ToUpper(text[6]) == 'D' && char.ToUpper(text[7]) == 'A' &&
char.ToUpper(text[8]) == 'Y'
)
return 4;
else if (text.Length == 8 && char.ToUpper(text[0]) == 'T' && char.ToUpper(text[1]) == 'H' &&
char.ToUpper(text[2]) == 'U' && char.ToUpper(text[3]) == 'R' &&
char.ToUpper(text[4]) == 'S' && char.ToUpper(text[5]) == 'D' &&
char.ToUpper(text[6]) == 'A' && char.ToUpper(text[7]) == 'Y'
)
return 8;
else if (text.Length == 6 && char.ToUpper(text[0]) == 'F' && char.ToUpper(text[1]) == 'R' &&
char.ToUpper(text[2]) == 'I' && char.ToUpper(text[3]) == 'D' &&
char.ToUpper(text[4]) == 'A' && char.ToUpper(text[5]) == 'Y'
)
return 16;
else if (text.Length == 8 && char.ToUpper(text[0]) == 'S' && char.ToUpper(text[1]) == 'A' &&
char.ToUpper(text[2]) == 'T' && char.ToUpper(text[3]) == 'U' &&
char.ToUpper(text[4]) == 'R' && char.ToUpper(text[5]) == 'D' &&
char.ToUpper(text[6]) == 'A' && char.ToUpper(text[7]) == 'Y'
)
return 32;
else if (text.Length == 6 && char.ToUpper(text[0]) == 'S' &&
char.ToUpper(text[1]) == 'U' && char.ToUpper(text[2]) == 'N' &&
char.ToUpper(text[3]) == 'D' && char.ToUpper(text[4]) == 'A' &&
char.ToUpper(text[5]) == 'Y'
)
return 64;
else if (text.Length == 8 && char.ToUpper(text[0]) == 'W' &&
char.ToUpper(text[1]) == 'E' && char.ToUpper(text[2]) == 'E' &&
char.ToUpper(text[3]) == 'K' && char.ToUpper(text[4]) == 'D' &&
char.ToUpper(text[5]) == 'A' && char.ToUpper(text[6]) == 'Y' &&
char.ToUpper(text[7]) == 'S'
)
return 31;
else if (text.Length == 8 && char.ToUpper(text[0]) == 'W' &&
char.ToUpper(text[1]) == 'E' && char.ToUpper(text[2]) == 'E' &&
char.ToUpper(text[3]) == 'K' && char.ToUpper(text[4]) == 'E' &&
char.ToUpper(text[5]) == 'N' && char.ToUpper(text[6]) == 'D' &&
char.ToUpper(text[7]) == 'S'
)
return 96;
else if (text.Length == 3 && char.ToUpper(text[0]) == 'A' &&
char.ToUpper(text[1]) == 'L' && char.ToUpper(text[2]) == 'L'
)
return 127;
else
//throw new FormatException("Enum of type 'DaysOfWeek' cannot be parsed. Valid values are: None or Monday or Tuesday or Wednesday or Thursday or Friday or Saturday or Sunday or Weekdays or Weekends or All or number within Byte range.");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment