kwqphonenumberparser.cpp
来自「最新Nokia手机浏览器全套源代码完美版。」· C++ 代码 · 共 134 行
CPP
134 行
#include <stdio.h>
#include <stdarg.h>
#include "KWQString.h"
// ----------------------------------------------------------------------------
// parseNumber
//
// Parse the telephone number from the wtai or tel scheme. Also check phone
// number from cti attribute, if present with tel scheme and aCti = true.
//
// TEL cases: <a href="tel:6175551234">
// <a href="tel:6175551234 cti=7815554321/67#,89*">
//
// Returns true if a valid number, false if not a valid number.
// ----------------------------------------------------------------------------
bool
parseNumber(QString number,
bool aCti)
{
QChar ch;
QString unesc = number;
bool valid = false;
int charCount = 0;
int digitCount = 0;
ch = unesc[0];
// Allow numbers to begin with the "+" char.
if (ch == '+')
{
charCount++;
ch = unesc[charCount];
}
// Parse the phone number, until we reach the end
while (ch != '\0')
{
// Do we have a valid digit
if (ch.isDigit())
{
charCount++;
ch = unesc[charCount];
digitCount++;
}
// Do we have a valid non-digit character
else if (ch.isSpace() ||
(ch == '#') ||
(ch == '*') ||
(ch == '.') ||
(ch == '(') ||
(ch == ')') ||
(ch == '-') ||
(ch == ','))
{
charCount++;
ch = unesc[charCount];
}
// Do we have a returnValue delimiter "!", or a parameter delimiter ";".
// We are at the end of the phone number.
// For example: wtai:\\wp\ap;6175551234;Joe Smith!retValue
else if ((ch == '!') || (ch ==';'))
{
break;
}
// Do we have a character that is only valid in a cti number
else if (ch == '/')
{
// If this a cti number, break and continue processing as cti number
if (aCti)
{
break;
}
// We have a non-cti number with invalid characters
else
{
return valid;
}
}
// We have an invalid character in the number, before we came to the end
else
{
return valid;
}
} // end of while loop
// Is our number an invalid length
if ((digitCount < 1) || (digitCount > 24))
{
return valid;
}
// If this is not a cti number, we are done
if (!aCti)
{
valid = true;
return valid;
}
// This is a cti number, continue parsing the output with cti specs
while (ch != '\0')
{
// Do we have a valid cti character
if (ch.isDigit() ||
(ch == '#') ||
(ch == '*') ||
(ch == ','))
{
charCount++;
ch = unesc[charCount];
}
// Do we have a slash, check if consecutive slashes
else if (ch == '/')
{
charCount++;
ch = unesc[charCount];
// Consecutive "/" (pause) are not allowed according to NTT DoCoMo's
// "I-Mode and C-Html difference" document (section 3), also wtai spec.
if (ch == '/')
{
return valid;
}
}
// We have an invalid character in the cti number, before we came to end
else
{
return valid;
}
} // end of while loop
valid = true;
return valid;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?