本文整理汇总了C#中System.Char.IsHex方法的典型用法代码示例。如果您正苦于以下问题:C# Char.IsHex方法的具体用法?C# Char.IsHex怎么用?C# Char.IsHex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Char
的用法示例。
在下文中一共展示了Char.IsHex方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnicodeRange
/// <summary>
/// 4.4.23. Unicode-range State
/// </summary>
CssToken UnicodeRange(Char current)
{
for (int i = 0; i < 6; i++)
{
if (!current.IsHex())
break;
_stringBuffer.Append(current);
current = Next;
}
if (_stringBuffer.Length != 6)
{
for (int i = 0; i < 6 - _stringBuffer.Length; i++)
{
if (current != Specification.QuestionMark)
{
current = Previous;
break;
}
_stringBuffer.Append(current);
current = Next;
}
var range = FlushBuffer();
var start = range.Replace(Specification.QuestionMark, '0');
var end = range.Replace(Specification.QuestionMark, 'F');
return CssToken.Range(start, end);
}
else if (current == Specification.Minus)
{
current = Next;
if (current.IsHex())
{
var start = _stringBuffer.ToString();
_stringBuffer.Clear();
for (int i = 0; i < 6; i++)
{
if (!current.IsHex())
{
current = Previous;
break;
}
_stringBuffer.Append(current);
current = Next;
}
var end = FlushBuffer();
return CssToken.Range(start, end);
}
else
{
Back(2);
return CssToken.Range(FlushBuffer(), null);
}
}
else
{
Back();
return CssToken.Range(FlushBuffer(), null);
}
}
示例2: 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());
}
示例3: ConsumeEscape
/// <summary>
/// Consumes an escaped character AFTER the solidus has already been
/// consumed.
/// </summary>
/// <returns>The escaped character.</returns>
String ConsumeEscape(Char current)
{
if (current.IsHex())
{
var escape = new List<Char>();
for (int i = 0; i < 6; i++)
{
escape.Add(current);
current = Next;
if (!current.IsHex())
break;
}
current = Previous;
var code = Int32.Parse(new String(escape.ToArray()), NumberStyles.HexNumber);
return Char.ConvertFromUtf32(code);
}
return current.ToString();
}
示例4: Data
//.........这里部分代码省略.........
return Data(Next);
return CssCommentToken.Open;
}
current = Previous;
}
current = Previous;
}
return CssToken.Delim(Previous);
case Specification.At:
return AtKeywordStart(Next);
case Specification.SquareBracketOpen:
return CssBracketToken.OpenSquare;
case Specification.SquareBracketClose:
return CssBracketToken.CloseSquare;
case Specification.Accent:
current = Next;
if (current == Specification.Equality)
return CssMatchToken.Prefix;
return CssToken.Delim(Previous);
case Specification.CurlyBracketOpen:
return CssBracketToken.OpenCurly;
case Specification.CurlyBracketClose:
return CssBracketToken.CloseCurly;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return NumberStart(current);
case 'U':
case 'u':
current = Next;
if (current == Specification.Plus)
{
current = Next;
if (current.IsHex() || current == Specification.QuestionMark)
return UnicodeRange(current);
current = Previous;
}
return IdentStart(Previous);
case Specification.Pipe:
current = Next;
if (current == Specification.Equality)
return CssMatchToken.Dash;
else if (current == Specification.Pipe)
return CssToken.Column;
return CssToken.Delim(Previous);
case Specification.Tilde:
current = Next;
if (current == Specification.Equality)
return CssMatchToken.Include;
return CssToken.Delim(Previous);
case Specification.EndOfFile:
return null;
case Specification.ExclamationMark:
current = Next;
if (current == Specification.Equality)
return CssMatchToken.Not;
return CssToken.Delim(Previous);
default:
if (current.IsNameStart())
return IdentStart(current);
return CssToken.Delim(current);
}
}
示例5: 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());
}
示例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: ConsumeEscape
/// <summary>
/// Consumes an escaped character AFTER the solidus has already been
/// consumed.
/// </summary>
/// <returns>The escaped character.</returns>
String ConsumeEscape(Char current)
{
if (current.IsHex())
{
var escape = new Char[6];
var length = 0;
while (length < escape.Length)
{
escape[length++] = current;
current = GetNext();
if (!current.IsHex())
break;
}
if (current != Symbols.Space)
Back();
var code = Int32.Parse(new String(escape, 0, length), NumberStyles.HexNumber);
if (code.IsInvalid() == false)
return code.ConvertFromUtf32();
current = Symbols.Replacement;
}
return current.ToString();
}
示例8: Data
//.........这里部分代码省略.........
if (current == Symbols.Minus)
return NewOpenComment();
current = GetPrevious();
}
current = GetPrevious();
}
return NewDelimiter(GetPrevious());
case Symbols.At:
return AtKeywordStart();
case Symbols.SquareBracketOpen:
return NewOpenSquare();
case Symbols.SquareBracketClose:
return NewCloseSquare();
case Symbols.Accent:
current = GetNext();
if (current == Symbols.Equality)
return NewPrefix();
return NewDelimiter(GetPrevious());
case Symbols.CurlyBracketOpen:
return NewOpenCurly();
case Symbols.CurlyBracketClose:
return NewCloseCurly();
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return NumberStart(current);
case 'U':
case 'u':
current = GetNext();
if (current == Symbols.Plus)
{
current = GetNext();
if (current.IsHex() || current == Symbols.QuestionMark)
return UnicodeRange(current);
current = GetPrevious();
}
return IdentStart(GetPrevious());
case Symbols.Pipe:
current = GetNext();
if (current == Symbols.Equality)
return NewDash();
else if (current == Symbols.Pipe)
return NewColumn();
return NewDelimiter(GetPrevious());
case Symbols.Tilde:
current = GetNext();
if (current == Symbols.Equality)
return NewInclude();
return NewDelimiter(GetPrevious());
case Symbols.EndOfFile:
return NewEof();
case Symbols.ExclamationMark:
current = GetNext();
if (current == Symbols.Equality)
return NewNot();
return NewDelimiter(GetPrevious());
default:
if (current.IsNameStart())
return IdentStart(current);
return NewDelimiter(current);
}
}
示例9: UnicodeRange
/// <summary>
/// 4.4.23. Unicode-range State
/// </summary>
CssToken UnicodeRange(Char current)
{
for (int i = 0; i < 6; i++)
{
if (!current.IsHex())
break;
_stringBuffer.Append(current);
current = GetNext();
}
if (_stringBuffer.Length != 6)
{
for (int i = 0; i < 6 - _stringBuffer.Length; i++)
{
if (current != Symbols.QuestionMark)
{
current = GetPrevious();
break;
}
_stringBuffer.Append(current);
current = GetNext();
}
return NewRange(FlushBuffer());
}
else if (current == Symbols.Minus)
{
current = GetNext();
if (current.IsHex())
{
var start = _stringBuffer.ToString();
_stringBuffer.Clear();
for (int i = 0; i < 6; i++)
{
if (!current.IsHex())
{
current = GetPrevious();
break;
}
_stringBuffer.Append(current);
current = GetNext();
}
var end = FlushBuffer();
return NewRange(start, end);
}
else
{
Back(2);
return NewRange(FlushBuffer());
}
}
else
{
Back();
return NewRange(FlushBuffer());
}
}
示例10: Data
//.........这里部分代码省略.........
return Data(_src.Next);
return CssCommentToken.Open;
}
current = _src.Previous;
}
current = _src.Previous;
}
return CssToken.Delim(_src.Previous);
case Specification.AT:
return AtKeywordStart(_src.Next);
case Specification.SBO:
return CssBracketToken.OpenSquare;
case Specification.SBC:
return CssBracketToken.CloseSquare;
case Specification.ACCENT:
current = _src.Next;
if (current == Specification.EQ)
return CssMatchToken.Prefix;
return CssToken.Delim(_src.Previous);
case Specification.CBO:
return CssBracketToken.OpenCurly;
case Specification.CBC:
return CssBracketToken.CloseCurly;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return NumberStart(current);
case 'U':
case 'u':
current = _src.Next;
if (current == Specification.PLUS)
{
current = _src.Next;
if (current.IsHex() || current == Specification.QM)
return UnicodeRange(current);
current = _src.Previous;
}
return IdentStart(_src.Previous);
case Specification.PIPE:
current = _src.Next;
if (current == Specification.EQ)
return CssMatchToken.Dash;
else if (current == Specification.PIPE)
return CssToken.Column;
return CssToken.Delim(_src.Previous);
case Specification.TILDE:
current = _src.Next;
if (current == Specification.EQ)
return CssMatchToken.Include;
return CssToken.Delim(_src.Previous);
case Specification.EOF:
return null;
case Specification.EM:
current = _src.Next;
if (current == Specification.EQ)
return CssMatchToken.Not;
return CssToken.Delim(_src.Previous);
default:
if (current.IsNameStart())
return IdentStart(current);
return CssToken.Delim(current);
}
}
示例11: CharacterReference
XmlEntityToken CharacterReference(Char c)
{
_stringBuffer.Clear();
if (c == Specification.NUM)
{
c = _src.Next;
while (c.IsHex())
{
_stringBuffer.Append(c);
c = _src.Next;
}
if (_stringBuffer.Length > 0 && c == Specification.SC)
return new XmlEntityToken { Value = _stringBuffer.ToString(), IsNumeric = true };
}
else if (c.IsNameStart())
{
do
{
_stringBuffer.Append(c);
c = _src.Next;
}
while (c.IsName());
if (c == Specification.SC)
return new XmlEntityToken { Value = _stringBuffer.ToString() };
}
throw new ArgumentException("Invalid entity reference.");
}
示例12: 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);
}
示例13: ConsumeEscape
String ConsumeEscape(Char current)
{
if (current.IsHex())
{
var isHex = true;
var escape = new Char[6];
var length = 0;
while (isHex && length < escape.Length)
{
escape[length++] = current;
current = GetNext();
isHex = current.IsHex();
}
if (!current.IsSpaceCharacter())
{
Back();
}
var code = Int32.Parse(new String(escape, 0, length), NumberStyles.HexNumber);
if (!code.IsInvalid())
{
return code.ConvertFromUtf32();
}
current = Symbols.Replacement;
}
return current.ToString();
}