/// <summary></summary> /// <param name="type"></param> /// <param name="noThrow">Does the caller want exceptions to be thrown on errors?</param> /// <param name="input"></param> /// <param name="errorState"></param> /// <returns>True if no error handling was needed. Else, an exception is throw (if allowed)</returns> static bool ParseHandleError(ParseErrorType type, bool noThrow, string input , TextStreamReadErrorState errorState) { Exception detailsException = null; switch (type) { case ParseErrorType.NoInput: if (noThrow) { return(false); } detailsException = new ArgumentException ("Input null or empty", nameof(input)); break; case ParseErrorType.InvalidValue: detailsException = new ArgumentException(string.Format (Util.InvariantCultureInfo, "Couldn't parse \"{0}\"", input), nameof(input)); break; default: return(true); } if (noThrow == false) { errorState.ThrowReadExeception(detailsException); } errorState.LogReadExceptionWarning(detailsException); return(true); }
public static bool ParseString(string input, ref bool value, bool noThrow , TextStreamReadErrorState errorState) { var result = ParseVerifyInput(input); if (result == ParseErrorType.None) { value = Text.Util.ParseBooleanLazy(input); } return(ParseHandleError(result, noThrow, input, errorState)); }
public static bool ParseString(string input, ref char value, bool noThrow , TextStreamReadErrorState errorState) { var result = ParseVerifyInput(input); if (result == ParseErrorType.None) { value = input[0]; } return(ParseHandleError(result, noThrow, input, errorState)); }
public static bool ParseString(string input, ref double value, bool noThrow , TextStreamReadErrorState errorState) { var result = ParseVerifyInput(input); if (result == ParseErrorType.None) { result = ParseVerifyResult(result, Numbers.DoubleTryParseInvariant(input, out value)); } return(ParseHandleError(result, noThrow, input, errorState)); }
public static bool ParseString(string input, ref float value, bool noThrow , TextStreamReadErrorState errorState) { var result = ParseVerifyInput(input); if (result == ParseErrorType.None) { // #HACK HaloWars data has floats with C-based 'f' suffix char last_char = input[input.Length - 1]; if (last_char == 'f' || last_char == 'F') { input = input.Substring(0, input.Length - 1); } result = ParseVerifyResult(result, Numbers.FloatTryParseInvariant(input, out value)); } return(ParseHandleError(result, noThrow, input, errorState)); }
protected TagElementTextStream() { mReadErrorState = new TextStreamReadErrorState(this); }