/// <summary> /// endWithが見つかるまで読み込む。始点と終端のチェックは呼び出し側で行うこと。 /// エスケープあり。 /// </summary> /// <param name="st"></param> /// <returns></returns> public static string ReadString(StringStream st, StrEndWith endWith) { StringBuilder buffer = new StringBuilder(100); while (true) { switch (st.Current) { case '\0': goto end; case '\"': if (endWith == StrEndWith.DoubleQuotation) { goto end; } break; case '\'': if (endWith == StrEndWith.SingleQuotation) { goto end; } break; case ',': if ((endWith == StrEndWith.Comma) || (endWith == StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon)) { goto end; } break; case '(': case '[': case ';': if (endWith == StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon) { goto end; } break; case '\\': //エスケープ処理 st.ShiftNext(); //\を読み飛ばす switch (st.Current) { case StringStream.EndOfString: throw new CodeEE("エスケープ文字\\の後に文字がありません"); case '\n': break; case 's': buffer.Append(' '); break; case 'S': buffer.Append(' '); break; case 't': buffer.Append('\t'); break; case 'n': buffer.Append('\n'); break; default: buffer.Append(st.Current); break; } st.ShiftNext(); //\の次の文字を読み飛ばす continue; } buffer.Append(st.Current); st.ShiftNext(); } end: return(buffer.ToString()); }
/// <summary> /// endWithが見つかるまで読み込む。始点と終端のチェックは呼び出し側で行うこと。 /// エスケープあり。 /// </summary> /// <param name="st"></param> /// <returns></returns> public static string ReadString(StringStream st, StrEndWith endWith) { StringBuilder buffer = new StringBuilder(100); while (true) { switch (st.Current) { case '\0': goto end; case '\"': if (endWith == StrEndWith.DoubleQuotation) goto end; break; case ',': if ((endWith == StrEndWith.Comma) || (endWith == StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon)) goto end; break; case '(': case '[': case ';': if (endWith == StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon) goto end; break; case '\\'://エスケープ処理 st.ShiftNext();//\を読み飛ばす switch (st.Current) { case StringStream.EndOfString: throw new CodeEE("エスケープ文字\\の後に文字がありません"); case '\n': break; case 's': buffer.Append(' '); break; case 'S': buffer.Append(' '); break; case 't': buffer.Append('\t'); break; case 'n': buffer.Append('\n'); break; default: buffer.Append(st.Current); break; } st.ShiftNext();//\の次の文字を読み飛ばす continue; } buffer.Append(st.Current); st.ShiftNext(); } end: return buffer.ToString(); }