本文整理汇总了C#中System.__DTString.GetDigit方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.GetDigit方法的具体用法?C# __DTString.GetDigit怎么用?C# __DTString.GetDigit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.__DTString
的用法示例。
在下文中一共展示了__DTString.GetDigit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseFractionExact
private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
{
if (!str.GetNextDigit())
{
str.Index--;
return false;
}
result = (double)str.GetDigit();
int i;
for (i = 1; i < maxDigitLen; i++)
{
if (!str.GetNextDigit())
{
str.Index--;
break;
}
result = result * 10.0 + (double)str.GetDigit();
}
result /= Math.Pow(10.0, (double)i);
return i == maxDigitLen;
}
示例2: ParseFractionExact
/*=================================ParseFractionExact==================================
**Action: Parse the number string in __DTString that are formatted using
** the following patterns:
** "0", "00", and "000..0"
**Returns: the fraction value
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if error in parsing number.
==============================================================================*/
private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result) {
if (!str.GetNextDigit()) {
str.Index--;
return false;
}
result = str.GetDigit();
int digitLen = 1;
for (; digitLen < maxDigitLen; digitLen++) {
if (!str.GetNextDigit()) {
str.Index--;
break;
}
result = result * 10 + str.GetDigit();
}
result = ((double)result / Math.Pow(10, digitLen));
return (digitLen == maxDigitLen);
}
示例3: ParseDigits
internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
{
result = 0;
int index = str.Index;
int i;
for (i = 0; i < maxDigitLen; i++)
{
if (!str.GetNextDigit())
{
str.Index--;
break;
}
result = result * 10 + str.GetDigit();
}
if (i < minDigitLen)
{
str.Index = index;
return false;
}
return true;
}
示例4: ParseFractionExact
private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result)
{
if (!str.GetNextDigit())
{
str.Index--;
return false;
}
result = str.GetDigit();
int num = 1;
while (num < maxDigitLen)
{
if (!str.GetNextDigit())
{
str.Index--;
break;
}
result = (result * 10.0) + str.GetDigit();
num++;
}
result = ((double) result) / Math.Pow(10.0, (double) num);
return (num == maxDigitLen);
}
示例5: ParseDigits
internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result) {
Contract.Assert(minDigitLen > 0, "minDigitLen > 0");
Contract.Assert(maxDigitLen < 9, "maxDigitLen < 9");
Contract.Assert(minDigitLen <= maxDigitLen, "minDigitLen <= maxDigitLen");
result = 0;
int startingIndex = str.Index;
int tokenLength = 0;
while (tokenLength < maxDigitLen) {
if (!str.GetNextDigit()) {
str.Index--;
break;
}
result = result * 10 + str.GetDigit();
tokenLength++;
}
if (tokenLength < minDigitLen) {
str.Index = startingIndex;
return false;
}
return true;
}
示例6: ParseDigits
internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDigitLen, out int result)
{
result = 0;
int index = str.Index;
int num2 = 0;
while (num2 < maxDigitLen)
{
if (!str.GetNextDigit())
{
str.Index--;
break;
}
result = (result * 10) + str.GetDigit();
num2++;
}
if (num2 < minDigitLen)
{
str.Index = index;
return false;
}
return true;
}
示例7: Lex
//.........这里部分代码省略.........
dtok.dtt = DTT_Era;
} else if (raw.timeMark == -1 && (timeMark = GetTimeMark(str, dtfi)) != -1) {
raw.timeMark = timeMark;
GetSeparator(str, raw, dtfi);
} else {
//
// Not a month name, not a day of week name. Check if this is one of the
// known date words. This is used to deal case like Spanish cultures, which
// uses 'de' in their Date string.
//
//
if (!str.MatchWords(dtfi.DateWords)) {
throw new FormatException(
String.Format(Environment.GetResourceString("Format_UnknowDateTimeWord"), str.Index));
}
GetSeparator(str, raw, dtfi);
}
} else if (Char.IsDigit(ch)) {
if (raw.numCount == 3) {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
//
// This is a digit.
//
int number = ch - '0';
int digitCount = 1;
//
// Collect other digits.
//
while (str.GetNextDigit())
{
number = number * 10 + str.GetDigit();
digitCount++;
}
// If the previous parsing state is DS_T_NNt (like 12:01), and we got another number,
// so we will have a terminal state DS_TX_NNN (like 12:01:02).
// If the previous parsing state is DS_T_Nt (like 12:), and we got another number,
// so we will have a terminal state DS_TX_NN (like 12:01:02).
//
// Look ahead to see if the following character is a decimal point or timezone offset.
// This enables us to parse time in the forms of:
// "11:22:33.1234" or "11:22:33-08".
if (dps == DS_T_NNt || dps == DS_T_Nt) {
char nextCh;
if ((str.Index < str.len - 1)) {
nextCh = str.Value[str.Index];
switch (nextCh) {
case '.':
if (dps == DS_T_NNt) {
// Yes, advance to the next character.
str.Index++;
// Collect the second fraction.
raw.fraction = ParseFraction(str);
}
break;
case '+':
case '-':
if (result.timeZoneUsed) {
// Should not have two timezone offsets.
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
result.timeZoneUsed = true;
result.timeZoneOffset = ParseTimeZone(str, nextCh);
示例8: ParseTimeZone
/*=================================ParseTimeZone==========================
**Action: Parse the timezone offset in the following format:
** "+8", "+08", "+0800", "+0800"
** This method is used by DateTime.Parse().
**Returns: The TimeZone offset.
**Arguments:
** str the parsing string
**Exceptions:
** FormatException if invalid timezone format is found.
============================================================================*/
private static TimeSpan ParseTimeZone(__DTString str, char offsetChar) {
// The hour/minute offset for timezone.
int hourOffset = 0;
int minuteOffset = 0;
if (str.GetNextDigit()) {
// Get the first digit, Try if we can parse timezone in the form of "+8".
hourOffset = str.GetDigit();
if (str.GetNextDigit()) {
// Parsing "+18"
hourOffset *= 10;
hourOffset += str.GetDigit();
if (str.GetNext()) {
char ch;
if (Char.IsDigit(ch = str.GetChar())) {
// Parsing "+1800"
// Put the char back, since we already get the char in the previous GetNext() call.
str.Index--;
if (ParseDigits(str, 2, true, out minuteOffset)) {
// ParseDigits() does not advance the char for us, so do it here.
str.Index++;
} else {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
} else if (ch == ':') {
// Parsing "+18:00"
if (ParseDigits(str, 2, true, out minuteOffset)) {
str.Index++;
} else {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
} else {
// Not a digit, not a colon, put this char back.
str.Index--;
}
}
}
// The next char is not a digit, so we get the timezone in the form of "+8".
} else {
// Invalid timezone: No numbers after +/-.
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
TimeSpan timezoneOffset = new TimeSpan(hourOffset, minuteOffset, 0);
if (offsetChar == '-') {
timezoneOffset = timezoneOffset.Negate();
}
return (timezoneOffset);
}
示例9: ParseFractionExact
/*=================================ParseFractionExact==================================
**Action: Parse the number string in __DTString that are formatted using
** the following patterns:
** "0", "00", and "000..0"
**Returns: the fraction value
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if error in parsing number.
==============================================================================*/
private static bool ParseFractionExact(__DTString str, int digitLen, bool isThrowExp, ref double result) {
if (!str.GetNextDigit()) {
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
result = str.GetDigit();
for (int i = 1; i < digitLen; i++) {
if (!str.GetNextDigit()) {
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
result = result * 10 + str.GetDigit();
}
result = ((double)result / Math.Pow(10, digitLen));
return (true);
}
示例10: ParseDigits
/*=================================ParseDigits==================================
**Action: Parse the number string in __DTString that are formatted using
** the following patterns:
** "0", "00", and "000..0"
**Returns: the integer value
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if error in parsing number.
==============================================================================*/
private static bool ParseDigits(__DTString str, int digitLen, bool isThrowExp, out int result) {
result = 0;
if (!str.GetNextDigit()) {
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
result = str.GetDigit();
if (digitLen == 1) {
// When digitLen == 1, we should able to parse number like "9" and "19". However,
// we won't go beyond two digits.
//
// So let's look ahead one character to see if it is a digit. If yes, add it to result.
if (str.GetNextDigit()) {
result = result * 10 + str.GetDigit();
} else {
// Not a digit, let's roll back the Index.
str.Index--;
}
} else if (digitLen == 2) {
if (!str.GetNextDigit()) {
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
result = result * 10 + str.GetDigit();
} else {
for (int i = 1; i < digitLen; i++) {
if (!str.GetNextDigit()) {
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
result = result * 10 + str.GetDigit();
}
}
return (true);
}