本文整理汇总了C#中System.IO.TextReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.Read方法的具体用法?C# TextReader.Read怎么用?C# TextReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextReader
的用法示例。
在下文中一共展示了TextReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateIndent
public static string CalculateIndent(TextReader code, int line, bool tabsToSpaces = false, int indentWidth = 4)
{
if(line < 2)
return string.Empty;
var eng = new IndentEngine(DFormattingOptions.CreateDStandard(), tabsToSpaces, indentWidth);
int curLine = 1;
const int lf = (int)'\n';
const int cr = (int)'\r';
int c;
while((c = code.Read()) != -1)
{
if(c == lf || c == cr)
{
if(c == cr && code.Peek() == lf)
code.Read();
if(++curLine > line)
break;
}
eng.Push((char)c);
}
return eng.ThisLineIndent;
}
示例2: Parse
public static bool Parse(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return false;
reader.Read();
return cur == 't';
}
示例3: ParseNullable
public static bool? ParseNullable(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
reader.Read();
return cur == 't';
}
示例4: Parse
public static DateTime Parse(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return DateTime.MinValue;
var res = ParseDate(reader, cur);
reader.Read();
return res;
}
示例5: CorrectIndent
public static void CorrectIndent(TextReader code, int startOffset, int endOffset, Action<int, int, string> documentReplace, DFormattingOptions options = null, ITextEditorOptions textStyle = null, bool formatLastLine = true)
{
textStyle = textStyle ?? TextEditorOptions.Default;
var eng = new IndentEngine(options ?? DFormattingOptions.CreateDStandard(), textStyle.TabsToSpaces, textStyle.IndentSize, textStyle.KeepAlignmentSpaces);
var replaceActions = new List<DFormattingVisitor.TextReplaceAction>();
int originalIndent = 0;
bool hadLineBreak = true;
int n = 0;
for (int i = 0; i <= endOffset && (n = code.Read()) != -1; i++)
{
if(n == '\r' || n == '\n')
{
if (i >= startOffset && !eng.LineBeganInsideString)
replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent));
hadLineBreak = true;
originalIndent = 0;
if (code.Peek() == '\n')
{
eng.Push((char)code.Read());
i++;
}
}
else if(hadLineBreak)
{
if(n == ' ' || n== '\t')
originalIndent++;
else
hadLineBreak = false;
// If there's code left, format the last line of the selection either
if (i == endOffset && formatLastLine)
endOffset++;
}
eng.Push((char)n);
}
// Also indent the last line if we're at the EOF.
if (code.Peek() == -1 || (formatLastLine && n != '\r' && n != '\n'))
{
if(!eng.LineBeganInsideString)
replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent));
}
// Perform replacements from the back of the document to the front - to ensure offset consistency
for(int k = replaceActions.Count - 1; k>=0; k--)
{
var rep = replaceActions[k];
if(rep.RemovalLength > 0 || rep.NewText.Length != 0)
documentReplace(rep.Offset, rep.RemovalLength, rep.NewText);
}
}
示例6: ParseNullable
public static DateTime? ParseNullable(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
var res = ParseDate(reader, cur);
reader.Read();
return res;
}
示例7: ParseCollection
public static List<byte[]> ParseCollection(TextReader reader, int context, bool allowNulls)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
var espaced = cur != '{';
if (espaced)
{
for (int i = 0; i < context; i++)
reader.Read();
}
var innerContext = context << 1;
var skipInner = innerContext + (innerContext << 1);
var list = new List<byte[]>();
cur = reader.Peek();
if (cur == '}')
reader.Read();
var emptyColl = allowNulls ? null : new byte[0];
while (cur != -1 && cur != '}')
{
cur = reader.Read();
if (cur == 'N')
{
reader.Read();
reader.Read();
reader.Read();
list.Add(emptyColl);
cur = reader.Read();
}
else
{
for (int i = 0; i < skipInner; i++)
reader.Read();
var item = new List<byte>(1024);
cur = reader.Read();
while (cur != -1 && cur != '"' && cur != '\\')
{
item.Add((byte)((CharLookup[cur] << 4) + CharLookup[reader.Read()]));
cur = reader.Read();
}
for (int i = 0; i < innerContext; i++)
cur = reader.Read();
list.Add(item.ToArray());
}
}
if (espaced)
{
for (int i = 0; i < context; i++)
reader.Read();
}
reader.Read();
return list;
}
示例8: ReadInt
public static int ReadInt(TextReader reader)
{
int result = reader.Read() - '0';
var input = reader.Read();
while (input >= '0' && input <= '9')
{
result = (result * 10) + input - '0';
input = reader.Read();
}
return result;
}
示例9: Parse
internal new static JBoolean Parse(TextReader reader)
{
SkipSpace(reader);
char firstChar = (char)reader.Read();
if (firstChar == 't')
{
int c2 = reader.Read();
int c3 = reader.Read();
int c4 = reader.Read();
if (c2 == 'r' && c3 == 'u' && c4 == 'e')
{
return new JBoolean(true);
}
}
else if (firstChar == 'f')
{
int c2 = reader.Read();
int c3 = reader.Read();
int c4 = reader.Read();
int c5 = reader.Read();
if (c2 == 'a' && c3 == 'l' && c4 == 's' && c5 == 'e')
{
return new JBoolean(false);
}
}
throw new FormatException();
}
示例10: ParseS3
private static S3 ParseS3(TextReader reader, int context, int innerContext, IServiceLocator locator)
{
for (int i = 0; i < context; i++)
reader.Read();
var bucket = StringConverter.Parse(reader, innerContext);
var key = StringConverter.Parse(reader, innerContext);
var length = IntConverter.Parse(reader);
var name = StringConverter.Parse(reader, innerContext);
var mimeType = StringConverter.Parse(reader, innerContext);
var metadata = HstoreConverter.Parse(reader, innerContext);
for (int i = 0; i < context; i++)
reader.Read();
reader.Read();
return new S3 { Bucket = bucket, Key = key, Length = length, Name = name, MimeType = mimeType, Metadata = metadata };
}
示例11: Parse
public static float Parse(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return 0;
return ParseFloat(reader, ref cur);
}
示例12: ParseNullable
public static Guid? ParseNullable(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
return ParseGuid(reader, cur);
}
示例13: Parse
public static Guid Parse(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return Guid.Empty;
return ParseGuid(reader, cur);
}
示例14: Parse
public static S3 Parse(TextReader reader, int context)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return null;
return ParseS3(reader, context, context << 1, null);
}
示例15: Parse
public static long Parse(TextReader reader)
{
var cur = reader.Read();
if (cur == ',' || cur == ')')
return 0;
return ParseLong(reader, ref cur);
}