本文整理汇总了C#中System.Char.IsDigit方法的典型用法代码示例。如果您正苦于以下问题:C# Char.IsDigit方法的具体用法?C# Char.IsDigit怎么用?C# Char.IsDigit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Char
的用法示例。
在下文中一共展示了Char.IsDigit方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CharacterReference
/// <summary>
/// Called once an & character is being seen.
/// </summary>
/// <param name="c">The next character after the & character.</param>
/// <returns>The entity token.</returns>
String CharacterReference(Char c)
{
var start = _stringBuffer.Length;
var hex = false;
var numeric = c == Symbols.Num;
if (numeric)
{
c = GetNext();
hex = c == 'x' || c == 'X';
if (hex)
{
c = GetNext();
while (c.IsHex())
{
_stringBuffer.Append(c);
c = GetNext();
}
}
else
{
while (c.IsDigit())
{
_stringBuffer.Append(c);
c = GetNext();
}
}
}
else if (c.IsXmlNameStart())
{
do
{
_stringBuffer.Append(c);
c = GetNext();
}
while (c.IsXmlName());
}
if (c == Symbols.Semicolon && _stringBuffer.Length > start)
{
var length = _stringBuffer.Length - start;
var content = _stringBuffer.ToString(start, length);
_stringBuffer.Remove(start, length);
if (numeric)
{
var number = numeric ? content.FromHex() : content.FromDec();
if (!number.IsValidAsCharRef())
throw XmlParseError.CharacterReferenceInvalidNumber.At(_position);
return number.ConvertFromUtf32();
}
else
{
var entity = _resolver.GetSymbol(content);
if (String.IsNullOrEmpty(entity))
throw XmlParseError.CharacterReferenceInvalidCode.At(_position);
return entity;
}
}
throw XmlParseError.CharacterReferenceNotTerminated.At(GetCurrentPosition());
}
示例2: SciNotation
/// <summary>
/// 4.4.16. SciNotation state
/// </summary>
CssToken SciNotation(Char current)
{
while (true)
{
if (current.IsDigit())
_stringBuffer.Append(current);
else
{
Back();
return CssToken.Number(FlushBuffer());
}
current = Next;
}
}
示例3: AppendCharacterReference
/// <summary>
/// See 8.2.4.69 Tokenizing character references
/// </summary>
/// <param name="c">The next input character.</param>
/// <param name="allowedCharacter">The additionally allowed character if there is one.</param>
void AppendCharacterReference(Char c, Char allowedCharacter = Symbols.Null)
{
if (c.IsSpaceCharacter() || c == Symbols.LessThan || c == Symbols.EndOfFile || c == Symbols.Ampersand || c == allowedCharacter)
{
Back();
_stringBuffer.Append(Symbols.Ampersand);
return;
}
var entity = default(String);
if (c == Symbols.Num)
{
var exp = 10;
var basis = 1;
var num = 0;
var nums = new List<Int32>();
c = GetNext();
var isHex = c == 'x' || c == 'X';
if (isHex)
{
exp = 16;
while ((c = GetNext()).IsHex())
nums.Add(c.FromHex());
}
else
{
while (c.IsDigit())
{
nums.Add(c.FromHex());
c = GetNext();
}
}
for (var i = nums.Count - 1; i >= 0; i--)
{
num += nums[i] * basis;
basis *= exp;
}
if (nums.Count == 0)
{
Back(2);
if (isHex)
Back();
RaiseErrorOccurred(HtmlParseError.CharacterReferenceWrongNumber);
_stringBuffer.Append(Symbols.Ampersand);
return;
}
if (c != Symbols.Semicolon)
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceSemicolonMissing);
Back();
}
if (Entities.IsInCharacterTable(num))
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidCode);
entity = Entities.GetSymbolFromTable(num);
}
else if (Entities.IsInvalidNumber(num))
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidNumber);
entity = Symbols.Replacement.ToString();
}
else
{
if (Entities.IsInInvalidRange(num))
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidRange);
entity = Entities.Convert(num);
}
}
else
{
var consumed = 0;
var start = InsertionPoint - 1;
var reference = new Char[31];
var index = 0;
var chr = Current;
do
{
if (chr == Symbols.Semicolon || !chr.IsName())
break;
reference[index++] = chr;
var value = new String(reference, 0, index);
chr = GetNext();
consumed++;
//.........这里部分代码省略.........
示例4: NumberRest
/// <summary>
/// 4.4.13. Number-rest state
/// </summary>
CssToken NumberRest(Char current)
{
while (true)
{
if (current.IsDigit())
_stringBuffer.Append(current);
else if (current.IsNameStart())
{
var number = FlushBuffer();
_stringBuffer.Append(current);
return Dimension(Next, number);
}
else if (IsValidEscape(current))
{
current = Next;
var number = FlushBuffer();
_stringBuffer.Append(ConsumeEscape(current));
return Dimension(Next, number);
}
else
break;
current = Next;
}
switch (current)
{
case Specification.Dot:
current = Next;
if (current.IsDigit())
{
_stringBuffer.Append(Specification.Dot).Append(current);
return NumberFraction(Next);
}
Back();
return CssToken.Number(FlushBuffer());
case '%':
return CssUnitToken.Percentage(FlushBuffer());
case 'e':
case 'E':
return NumberExponential(current);
case Specification.Minus:
return NumberDash(current);
default:
Back();
return CssToken.Number(FlushBuffer());
}
}
示例5: NumberStart
/// <summary>
/// 4.4.12. Number state
/// </summary>
CssToken NumberStart(Char current)
{
while (true)
{
if (current == Specification.Plus || current == Specification.Minus)
{
_stringBuffer.Append(current);
current = Next;
if (current == Specification.Dot)
{
_stringBuffer.Append(current);
_stringBuffer.Append(Next);
return NumberFraction(Next);
}
_stringBuffer.Append(current);
return NumberRest(Next);
}
else if (current == Specification.Dot)
{
_stringBuffer.Append(current);
_stringBuffer.Append(Next);
return NumberFraction(Next);
}
else if (current.IsDigit())
{
_stringBuffer.Append(current);
return NumberRest(Next);
}
current = Next;
}
}
示例6: EReference
protected String EReference(Char c)
{
var buffer = Pool.NewStringBuilder();
if (c.IsXmlNameStart())
{
do
{
buffer.Append(c);
c = _stream.Next;
}
while (c.IsXmlName());
var temp = buffer.ToPool();
if (temp.Length > 0 && c == Specification.SC)
{
var p = _container.GetEntity(temp);
if (p != null)
return p.NodeValue;
}
}
else if (c == Specification.NUM)
{
c = _src.Next;
var hex = c == 'x' || c == 'X';
if (hex)
c = _stream.Next;
while (hex ? c.IsHex() : c.IsDigit())
{
buffer.Append(c);
c = _src.Next;
}
var temp = buffer.ToPool();
if (temp.Length > 0 && c == Specification.SC)
{
var num = hex ? temp.FromHex() : temp.FromDec();
if (num.IsValidAsCharRef())
return Char.ConvertFromUtf32(num);
throw Errors.Xml(ErrorCode.CharacterReferenceInvalidNumber);
}
}
throw Errors.Xml(ErrorCode.CharacterReferenceNotTerminated);
}
示例7: NumberExponential
/// <summary>
/// Substate of several Number states.
/// </summary>
CssToken NumberExponential(Char current)
{
current = Next;
if (current.IsDigit())
{
_stringBuffer.Append('e').Append(current);
return SciNotation(Next);
}
else if (current == Specification.Plus || current == Specification.Minus)
{
var op = current;
current = Next;
if (current.IsDigit())
{
_stringBuffer.Append('e').Append(op).Append(current);
return SciNotation(Next);
}
Back();
}
current = Previous;
var number = FlushBuffer();
_stringBuffer.Append(current);
return Dimension(Next, number);
}
示例8: CharacterReference
/// <summary>
/// See 8.2.4.69 Tokenizing character references
/// </summary>
/// <param name="c">The next input character.</param>
/// <param name="allowedCharacter">The additionally allowed character if there is one.</param>
String CharacterReference(Char c, Char allowedCharacter = Specification.NULL)
{
if (c.IsSpaceCharacter() || c == Specification.LT || c == Specification.EOF || c == Specification.AMPERSAND || c == allowedCharacter)
{
_src.Back();
return null;
}
if (c == Specification.NUM)
{
var exp = 10;
var basis = 1;
var num = 0;
var nums = new List<Int32>();
c = _src.Next;
var isHex = c == 'x' || c == 'X';
if (isHex)
{
exp = 16;
while ((c = _src.Next).IsHex())
nums.Add(c.FromHex());
}
else
{
while (c.IsDigit())
{
nums.Add(c.FromHex());
c = _src.Next;
}
}
for (var i = nums.Count - 1; i >= 0; i--)
{
num += nums[i] * basis;
basis *= exp;
}
if (nums.Count == 0)
{
_src.Back(2);
if (isHex)
_src.Back();
RaiseErrorOccurred(ErrorCode.CharacterReferenceWrongNumber);
return null;
}
if (c != Specification.SC)
{
RaiseErrorOccurred(ErrorCode.CharacterReferenceSemicolonMissing);
_src.Back();
}
if (Entities.IsInCharacterTable(num))
{
RaiseErrorOccurred(ErrorCode.CharacterReferenceInvalidCode);
return Entities.GetSymbolFromTable(num);
}
if (Entities.IsInvalidNumber(num))
{
RaiseErrorOccurred(ErrorCode.CharacterReferenceInvalidNumber);
return Specification.REPLACEMENT.ToString();
}
if (Entities.IsInInvalidRange(num))
RaiseErrorOccurred(ErrorCode.CharacterReferenceInvalidRange);
return Entities.Convert(num);
}
else
{
var last = String.Empty;
var consumed = 0;
var start = _src.InsertionPoint - 1;
var reference = new Char[31];
var index = 0;
var chr = _src.Current;
do
{
if (chr == Specification.SC || !chr.IsName())
break;
reference[index++] = chr;
var value = new String(reference, 0, index);
chr = _src.Next;
consumed++;
value = chr == Specification.SC ? Entities.GetSymbol(value) : Entities.GetSymbolWithoutSemicolon(value);
if (value != null)
{
//.........这里部分代码省略.........
示例9: TextDeclVersion
/// <summary>
/// Gets the version specified in the text declaration.
/// </summary>
/// <param name="c">The character.</param>
/// <param name="decl">The current declaration.</param>
/// <returns>The token.</returns>
DtdToken TextDeclVersion(Char c, DtdDeclToken decl)
{
if (c == Specification.EQ)
{
var q = _stream.Next;
if (q == Specification.DQ || q == Specification.SQ)
{
_stringBuffer.Clear();
c = _stream.Next;
while (c.IsDigit() || c == Specification.DOT)
{
_stringBuffer.Append(c);
c = _stream.Next;
}
if (c == q)
{
decl.Version = _stringBuffer.ToString();
return TextDeclBetween(_stream.Next, decl);
}
}
}
throw Errors.Xml(ErrorCode.DtdTextDeclInvalid);
}
示例10: GetNumericCharacterReference
private String GetNumericCharacterReference(Char c)
{
var exp = 10;
var basis = 1;
var num = 0;
var nums = new List<Int32>();
var isHex = c == 'x' || c == 'X';
if (isHex)
{
exp = 16;
while ((c = GetNext()).IsHex())
{
nums.Add(c.FromHex());
}
}
else
{
while (c.IsDigit())
{
nums.Add(c.FromHex());
c = GetNext();
}
}
for (var i = nums.Count - 1; i >= 0; i--)
{
num += nums[i] * basis;
basis *= exp;
}
if (nums.Count == 0)
{
Back(2);
if (isHex)
{
Back();
}
RaiseErrorOccurred(HtmlParseError.CharacterReferenceWrongNumber);
return null;
}
if (c != Symbols.Semicolon)
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceSemicolonMissing);
Back();
}
if (HtmlEntityService.IsInCharacterTable(num))
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidCode);
return HtmlEntityService.GetSymbolFromTable(num);
}
else if (HtmlEntityService.IsInvalidNumber(num))
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidNumber);
return Symbols.Replacement.ToString();
}
else if (HtmlEntityService.IsInInvalidRange(num))
{
RaiseErrorOccurred(HtmlParseError.CharacterReferenceInvalidRange);
}
return num.ConvertFromUtf32();
}
示例11: CharacterReference
/// <summary>
/// Called once an & character is being seen.
/// </summary>
/// <param name="c">The next character after the & character.</param>
/// <returns>The entity token.</returns>
XmlEntityToken CharacterReference(Char c)
{
if (c == Symbols.Num)
{
c = GetNext();
var isHex = c == 'x' || c == 'X';
if (isHex)
{
c = GetNext();
while (c.IsHex())
{
_stringBuffer.Append(c);
c = GetNext();
}
}
else
{
while (c.IsDigit())
{
_stringBuffer.Append(c);
c = GetNext();
}
}
if (_stringBuffer.Length > 0 && c == Symbols.Semicolon)
return NewEntity(numeric: true, hex: isHex);
}
else if (c.IsXmlNameStart())
{
do
{
_stringBuffer.Append(c);
c = GetNext();
}
while (c.IsXmlName());
if (c == Symbols.Semicolon)
return NewEntity();
}
throw XmlParseError.CharacterReferenceNotTerminated.At(GetCurrentPosition());
}
示例12: NumberStart
/// <summary>
/// 4.4.12. Number state
/// </summary>
CssToken NumberStart(Char current)
{
while (true)
{
if (current == Symbols.Plus || current == Symbols.Minus)
{
_stringBuffer.Append(current);
current = GetNext();
if (current == Symbols.Dot)
{
_stringBuffer.Append(current);
_stringBuffer.Append(GetNext());
return NumberFraction();
}
_stringBuffer.Append(current);
return NumberRest();
}
else if (current == Symbols.Dot)
{
_stringBuffer.Append(current);
_stringBuffer.Append(GetNext());
return NumberFraction();
}
else if (current.IsDigit())
{
_stringBuffer.Append(current);
return NumberRest();
}
current = GetNext();
}
}
示例13: NumberStart
/// <summary>
/// 4.4.12. Number state
/// </summary>
CssToken NumberStart(Char current)
{
while (true)
{
if (current == Specification.PLUS || current == Specification.MINUS)
{
_stringBuffer.Append(current);
current = _src.Next;
if (current == Specification.DOT)
{
_stringBuffer.Append(current);
_stringBuffer.Append(_src.Next);
return NumberFraction(_src.Next);
}
_stringBuffer.Append(current);
return NumberRest(_src.Next);
}
else if (current == Specification.DOT)
{
_stringBuffer.Append(current);
_stringBuffer.Append(_src.Next);
return NumberFraction(_src.Next);
}
else if (current.IsDigit())
{
_stringBuffer.Append(current);
return NumberRest(_src.Next);
}
current = _src.Next;
}
}
示例14: CharacterReference
/// <summary>
/// Called once an & character is being seen.
/// </summary>
/// <param name="c">The next character after the & character.</param>
/// <returns>The entity token.</returns>
XmlEntityToken CharacterReference(Char c)
{
var buffer = Pool.NewStringBuilder();
if (c == Specification.NUM)
{
c = _src.Next;
var hex = c == 'x' || c == 'X';
if (hex)
{
c = _src.Next;
while (c.IsHex())
{
buffer.Append(c);
c = _src.Next;
}
}
else
{
while (c.IsDigit())
{
buffer.Append(c);
c = _src.Next;
}
}
if (buffer.Length > 0 && c == Specification.SC)
return new XmlEntityToken { Value = buffer.ToPool(), IsNumeric = true, IsHex = hex };
}
else if (c.IsXmlNameStart())
{
do
{
buffer.Append(c);
c = _src.Next;
}
while (c.IsXmlName());
if (c == Specification.SC)
return new XmlEntityToken { Value = buffer.ToPool() };
}
buffer.ToPool();
throw Errors.Xml(ErrorCode.CharacterReferenceNotTerminated);
}