internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { HebrewNumber.HebrewToken hebrewToken; if ((int)ch == 39) { hebrewToken = HebrewNumber.HebrewToken.SingleQuote; } else if ((int)ch == 34) { hebrewToken = HebrewNumber.HebrewToken.DoubleQuote; } else { int index = (int)ch - 1488; if (index < 0 || index >= HebrewNumber.HebrewValues.Length) { return(HebrewNumberParsingState.NotHebrewDigit); } hebrewToken = HebrewNumber.HebrewValues[index].token; if (hebrewToken == HebrewNumber.HebrewToken.Invalid) { return(HebrewNumberParsingState.NotHebrewDigit); } context.result += HebrewNumber.HebrewValues[index].value; } context.state = HebrewNumber.NumberPasingState[(int)context.state][(int)hebrewToken]; if (context.state == HebrewNumber.HS._err) { return(HebrewNumberParsingState.InvalidHebrewNumber); } return(context.state == HebrewNumber.HS.END ? HebrewNumberParsingState.FoundEndOfHebrewNumber : HebrewNumberParsingState.ContinueParsing); }
//////////////////////////////////////////////////////////////////////// // // Actions: // Parse the Hebrew number by passing one character at a time. // The state between characters are maintained at HebrewNumberPasingContext. // Returns: // Return a enum of HebrewNumberParsingState. // NotHebrewDigit: The specified ch is not a valid Hebrew digit. // InvalidHebrewNumber: After parsing the specified ch, it will lead into // an invalid Hebrew number text. // FoundEndOfHebrewNumber: A terminal state is reached. This means that // we find a valid Hebrew number text after the specified ch is parsed. // ContinueParsing: The specified ch is a valid Hebrew digit, and // it will lead into a valid state in the state machine, we should // continue to parse incoming characters. // //////////////////////////////////////////////////////////////////////// internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { Debug.Assert(s_numberPasingState.Length == HebrewTokenCount * ((int)HS.S9_DQ + 1)); HebrewToken token; if (ch == '\'') { token = HebrewToken.SingleQuote; } else if (ch == '\"') { token = HebrewToken.DoubleQuote; } else { int index = (int)ch - minHebrewNumberCh; if (index >= 0 && index < s_hebrewValues.Length) { token = s_hebrewValues[index].token; if (token == HebrewToken.Invalid) { return(HebrewNumberParsingState.NotHebrewDigit); } context.result += s_hebrewValues[index].value; } else { // Not in valid Hebrew digit range. return(HebrewNumberParsingState.NotHebrewDigit); } } context.state = s_numberPasingState[(int)context.state * (int)HebrewTokenCount + (int)token]; if (context.state == HS._err) { // Invalid Hebrew state. This indicates an incorrect Hebrew number. return(HebrewNumberParsingState.InvalidHebrewNumber); } if (context.state == HS.END) { // Reach a terminal state. return(HebrewNumberParsingState.FoundEndOfHebrewNumber); } // We should continue to parse. return(HebrewNumberParsingState.ContinueParsing); }
internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { HebrewToken singleQuote; if (ch == '\'') { singleQuote = HebrewToken.SingleQuote; } else if (ch == '"') { singleQuote = HebrewToken.DoubleQuote; } else { int index = ch - 'א'; if ((index < 0) || (index >= HebrewValues.Length)) { return(HebrewNumberParsingState.NotHebrewDigit); } singleQuote = HebrewValues[index].token; if (singleQuote == HebrewToken.Invalid) { return(HebrewNumberParsingState.NotHebrewDigit); } context.result += HebrewValues[index].value; } context.state = NumberPasingState[(int)context.state][(int)singleQuote]; if (context.state == HS._err) { return(HebrewNumberParsingState.InvalidHebrewNumber); } if (context.state == HS.END) { return(HebrewNumberParsingState.FoundEndOfHebrewNumber); } return(HebrewNumberParsingState.ContinueParsing); }
// Token: 0x060031BF RID: 12735 RVA: 0x000BFA7C File Offset: 0x000BDC7C internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { HebrewNumber.HebrewToken hebrewToken; if (ch == '\'') { hebrewToken = HebrewNumber.HebrewToken.SingleQuote; } else if (ch == '"') { hebrewToken = HebrewNumber.HebrewToken.DoubleQuote; } else { int num = (int)(ch - 'א'); if (num < 0 || num >= HebrewNumber.HebrewValues.Length) { return(HebrewNumberParsingState.NotHebrewDigit); } hebrewToken = HebrewNumber.HebrewValues[num].token; if (hebrewToken == HebrewNumber.HebrewToken.Invalid) { return(HebrewNumberParsingState.NotHebrewDigit); } context.result += HebrewNumber.HebrewValues[num].value; } context.state = HebrewNumber.NumberPasingState[(int)context.state][(int)hebrewToken]; if (context.state == HebrewNumber.HS._err) { return(HebrewNumberParsingState.InvalidHebrewNumber); } if (context.state == HebrewNumber.HS.END) { return(HebrewNumberParsingState.FoundEndOfHebrewNumber); } return(HebrewNumberParsingState.ContinueParsing); }
internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { HebrewToken singleQuote; if (ch == '\'') { singleQuote = HebrewToken.SingleQuote; } else if (ch == '"') { singleQuote = HebrewToken.DoubleQuote; } else { int index = ch - 'א'; if ((index < 0) || (index >= HebrewValues.Length)) { return HebrewNumberParsingState.NotHebrewDigit; } singleQuote = HebrewValues[index].token; if (singleQuote == HebrewToken.Invalid) { return HebrewNumberParsingState.NotHebrewDigit; } context.result += HebrewValues[index].value; } context.state = NumberPasingState[(int) context.state][(int) singleQuote]; if (context.state == HS._err) { return HebrewNumberParsingState.InvalidHebrewNumber; } if (context.state == HS.END) { return HebrewNumberParsingState.FoundEndOfHebrewNumber; } return HebrewNumberParsingState.ContinueParsing; }
//////////////////////////////////////////////////////////////////////// // // Actions: // Try to parse the current word to see if it is a Hebrew number. // Tokens will be updated accordingly. // This is called by the Lexer of DateTime.Parse(). // // Unlike most of the functions in this class, the return value indicates // whether or not it started to parse. The badFormat parameter indicates // if parsing began, but the format was bad. // //////////////////////////////////////////////////////////////////////// private static bool TryParseHebrewNumber( ref __DTString str, out Boolean badFormat, out int number) { number = -1; badFormat = false; int i = str.Index; if (!HebrewNumber.IsDigit(str.Value[i])) { // If the current character is not a Hebrew digit, just return false. // There is no chance that we can parse a valid Hebrew number from here. return (false); } // The current character is a Hebrew digit. Try to parse this word as a Hebrew number. HebrewNumberParsingContext context = new HebrewNumberParsingContext(0); HebrewNumberParsingState state; do { state = HebrewNumber.ParseByChar(str.Value[i++], ref context); switch (state) { case HebrewNumberParsingState.InvalidHebrewNumber: // Not a valid Hebrew number. case HebrewNumberParsingState.NotHebrewDigit: // The current character is not a Hebrew digit character. // Break out so that we don't continue to try parse this as a Hebrew number. return (false); } } while (i < str.Value.Length && (state != HebrewNumberParsingState.FoundEndOfHebrewNumber)); // When we are here, we are either at the end of the string, or we find a valid Hebrew number. Contract.Assert(state == HebrewNumberParsingState.ContinueParsing || state == HebrewNumberParsingState.FoundEndOfHebrewNumber, "Invalid returned state from HebrewNumber.ParseByChar()"); if (state != HebrewNumberParsingState.FoundEndOfHebrewNumber) { // We reach end of the string but we can't find a terminal state in parsing Hebrew number. return (false); } // We have found a valid Hebrew number. Update the index. str.Advance(i - str.Index); // Get the final Hebrew number value from the HebrewNumberParsingContext. number = context.result; return (true); }
internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number) { number = 0; HebrewNumberParsingContext hebrewNumberParsingContext = new HebrewNumberParsingContext(0); HebrewNumberParsingState hebrewNumberParsingState = HebrewNumberParsingState.ContinueParsing; while (hebrewNumberParsingState == HebrewNumberParsingState.ContinueParsing && str.GetNext()) { hebrewNumberParsingState = HebrewNumber.ParseByChar(str.GetChar(), ref hebrewNumberParsingContext); } if (hebrewNumberParsingState == HebrewNumberParsingState.FoundEndOfHebrewNumber) { number = hebrewNumberParsingContext.result; return true; } return false; }
//////////////////////////////////////////////////////////////////////// // // Actions: // Parse the current word as a Hebrew number. // This is used by DateTime.ParseExact(). // //////////////////////////////////////////////////////////////////////// internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number) { number = 0; // Create a context object so that we can parse the Hebrew number text character by character. HebrewNumberParsingContext context = new HebrewNumberParsingContext(0); // Set this to ContinueParsing so that we will run the following while loop in the first time. HebrewNumberParsingState state = HebrewNumberParsingState.ContinueParsing; while (state == HebrewNumberParsingState.ContinueParsing && str.GetNext()) { state = HebrewNumber.ParseByChar(str.GetChar(), ref context); } if (state == HebrewNumberParsingState.FoundEndOfHebrewNumber) { // If we have reached a terminal state, update the result and returns. number = context.result; return (true); } // If we run out of the character before reaching FoundEndOfHebrewNumber, or // the state is InvalidHebrewNumber or ContinueParsing, we fail to match a Hebrew number. // Return an error. return false; }
//////////////////////////////////////////////////////////////////////// // // Actions: // Parse the Hebrew number by passing one character at a time. // The state between characters are maintained at HebrewNumberPasingContext. // Returns: // Return a enum of HebrewNumberParsingState. // NotHebrewDigit: The specified ch is not a valid Hebrew digit. // InvalidHebrewNumber: After parsing the specified ch, it will lead into // an invalid Hebrew number text. // FoundEndOfHebrewNumber: A terminal state is reached. This means that // we find a valid Hebrew number text after the specified ch is parsed. // ContinueParsing: The specified ch is a valid Hebrew digit, and // it will lead into a valid state in the state machine, we should // continue to parse incoming characters. // //////////////////////////////////////////////////////////////////////// internal static HebrewNumberParsingState ParseByChar(char ch, ref HebrewNumberParsingContext context) { HebrewToken token; if (ch == '\'') { token = HebrewToken.SingleQuote; } else if (ch == '\"') { token = HebrewToken.DoubleQuote; } else { int index = (int)ch - minHebrewNumberCh; if (index >= 0 && index < HebrewValues.Length ) { token = HebrewValues[index].token; if (token == HebrewToken.Invalid) { return (HebrewNumberParsingState.NotHebrewDigit); } context.result += HebrewValues[index].value; } else { // Not in valid Hebrew digit range. return (HebrewNumberParsingState.NotHebrewDigit); } } context.state = NumberPasingState[(int)context.state][(int)token]; if (context.state == HS._err) { // Invalid Hebrew state. This indicates an incorrect Hebrew number. return (HebrewNumberParsingState.InvalidHebrewNumber); } if (context.state == HS.END) { // Reach a terminal state. return (HebrewNumberParsingState.FoundEndOfHebrewNumber); } // We should continue to parse. return (HebrewNumberParsingState.ContinueParsing); }
private static bool TryParseHebrewNumber(ref __DTString str, out bool badFormat, out int number) { number = -1; badFormat = false; int index = str.Index; if (!HebrewNumber.IsDigit(str.Value[index])) return false; HebrewNumberParsingContext context = new HebrewNumberParsingContext(0); HebrewNumberParsingState numberParsingState; do { numberParsingState = HebrewNumber.ParseByChar(str.Value[index++], ref context); switch (numberParsingState) { case HebrewNumberParsingState.InvalidHebrewNumber: case HebrewNumberParsingState.NotHebrewDigit: return false; default: continue; } } while (index < str.Value.Length && numberParsingState != HebrewNumberParsingState.FoundEndOfHebrewNumber); if (numberParsingState != HebrewNumberParsingState.FoundEndOfHebrewNumber) return false; str.Advance(index - str.Index); number = context.result; return true; }