String WifiTile::RemoveDoubleQuotes(
    /* [in] */ const String& string)
{
    if (string == NULL) return String(NULL);
    const Int32 length = string.GetLength();
    if ((length > 1) && (string.GetChar(0) == '"') && (string.GetChar(length - 1) == '"')) {
        return string.Substring(1, length - 1);
    }
    return string;
}
Example #2
0
AutoPtr<ArrayOf<Byte> > HexDump::HexStringToByteArray(
    /* [in] */ const String& hexString)
{
    Int32 length = hexString.GetLength();
    AutoPtr<ArrayOf<Byte> > buffer = ArrayOf<Byte>::Alloc(length / 2);

    for (Int32 i = 0; i < length; i += 2) {
        (*buffer)[i / 2] = (Byte)((ToByte(hexString.GetChar(i)) << 4) | ToByte(hexString.GetChar(i+1)));
    }

    return buffer;
}
Example #3
0
Int32 CSplitClockView::GetAmPmPartEndIndex(
    /* [in] */ const String& formatString)
{
    Boolean hasAmPm = FALSE;
    Int32 length = formatString.GetLength();
    for (Int32 i = length - 1; i >= 0; i--) {
        Char32 c = formatString.GetChar(i);
        Boolean isAmPm = c == 'a';
        Boolean isWhitespace = Character::IsWhitespace(c);
        if (isAmPm) {
            hasAmPm = TRUE;
        }
        if (isAmPm || isWhitespace) {
            continue;
        }
        if (i == length - 1) {

            // First character was not AM/PM and not whitespace, so it's not ending with AM/PM.
            return -1;
        } else {

            // If we have AM/PM at all, return last index, or -1 to indicate that it's not
            // ending with AM/PM.
            return hasAmPm ? i + 1 : -1;
        }
    }

    // Only AM/PM and whitespaces? The whole string is AM/PM. Else: Only whitespaces in the
    // string.
    return hasAmPm ? 0 : -1;
}
Example #4
0
String UrlUtils::CanonicalizePath(
    /* [in] */ const String& _path,
    /* [in] */ Boolean discardRelativePrefix)
{
    String path = _path;
    // the first character of the current path segment
    Int32 segmentStart = 0;

    // the number of segments seen thus far that can be erased by sequences of '..'.
    Int32 deletableSegments = 0;

    for (Int32 i = 0; i <= path.GetLength(); ) {
        Int32 nextSegmentStart;
        if (i == path.GetLength()) {
            nextSegmentStart = i;
        } else if (path.GetChar(i) == '/') {
            nextSegmentStart = i + 1;
        } else {
            i++;
            continue;
        }

        /*
         * We've encountered either the end of a segment or the end of the
         * complete path. If the final segment was "." or "..", remove the
         * appropriate segments of the path.
         */
        if (i == segmentStart + 1 && path.RegionMatches(segmentStart, String("."), 0, 1)) {
            // Given "abc/def/./ghi", remove "./" to get "abc/def/ghi".
            String part = path.Substring(0, segmentStart);
            part += path.Substring(nextSegmentStart);
            path = part;
            i = segmentStart;
        }
        else if (i == segmentStart + 2 && path.RegionMatches(segmentStart, String(".."), 0, 2)) {
            if (deletableSegments > 0 || discardRelativePrefix) {
                // Given "abc/def/../ghi", remove "def/../" to get "abc/ghi".
                deletableSegments--;
                Int32 prevSegmentStart = path.LastIndexOf('/', segmentStart - 2) + 1;
                String part = path.Substring(0, prevSegmentStart);
                part += path.Substring(nextSegmentStart);
                path = part;
                i = segmentStart = prevSegmentStart;
            }
            else {
                // There's no segment to delete; this ".." segment must be retained.
                i++;
                segmentStart = i;
            }
        }
        else {
            if (i > 0) {
                deletableSegments++;
            }
            i++;
            segmentStart = i;
        }
    }
    return path;
}
Char32 CMenuInflater::MenuState::GetShortcut(
    /* [in] */ const String& shortcutString)
{
    if (shortcutString.IsNull()) {
        return 0;
    }
    else {
        return shortcutString.GetChar(0);
    }
}
Example #6
0
Int32 AbstractVerifier::CountDots(
    /* [in] */ const String& s)
{
    Int32 count = 0;
    for (Int32 i = 0; i < s.GetLength(); i++) {
        if(s.GetChar(i) == '.') {
            count++;
        }
    }
    return count;
}
String TextIOHandler::getLine() {
	String result;
	Char buffer[2048];
	while (!feof(stdin)) {
		if (!IF_UNICODE(fgetws,fgets)(buffer, 2048, stdin)) {
			return result; // error
		}
		result += buffer;
		if (result.GetChar(result.size()-1) == _('\n')) {
			// drop newline, done
			result.resize(result.size() - 1);
			return result;
		}
	}
	return result;
}
Example #8
0
StringFilter* StringFilter::GetFilter(
    /* [in] */ ValueProvider* valueProvider,
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ Int32 attributeIndex)
{
    String attributeName;
    String attriValue;
    parser->GetAttributeName(attributeIndex, &attributeName);
    parser->GetAttributeValue(attributeIndex, &attriValue);

    switch (attributeName.GetChar(0)) {
        case 'e':
            if (!attributeName.Equals(ATTR_EQUALS)) {
                return NULL;
            }
            return new EqualsFilter(valueProvider, attriValue);
        case 'i':
            if (!attributeName.Equals(ATTR_IS_NULL)) {
                return NULL;
            }
            return new IsNullFilter(valueProvider, attriValue);
        case 's':
            if (!attributeName.Equals(ATTR_STARTS_WITH)) {
                return NULL;
            }
            return new StartsWithFilter(valueProvider, attriValue);
        case 'c':
            if (!attributeName.Equals(ATTR_CONTAINS)) {
                return NULL;
            }
            return new ContainsFilter(valueProvider, attriValue);
        case 'p':
            if (!attributeName.Equals(ATTR_PATTERN)) {
                return NULL;
            }
            return new PatternStringFilter(valueProvider, attriValue);
        case 'r':
            if (!attributeName.Equals(ATTR_REGEX)) {
                return NULL;
            }
            return new RegexFilter(valueProvider, attriValue);
    }
    return NULL;
}
Example #9
0
AutoPtr<ITimeZone> TimeZone::GetCustomTimeZone(
    /* [in] */ const String& id)
{
    AutoPtr<IMatcher> m;
    CUSTOM_ZONE_ID_PATTERN->Matcher(id, (IMatcher**)&m);
    Boolean isMatches = FALSE;
    m->Matches(&isMatches);
    if (!isMatches) {
        return NULL;
    }

    Int32 hour = 0;
    Int32 minute = 0;
    String grstr;
    (IMatchResult::Probe(m))->Group(1 , &grstr);
    hour = StringUtils::ParseInt32(grstr);
    (IMatchResult::Probe(m))->Group(3, &grstr);
    if (!grstr.IsNull()) {
        minute = StringUtils::ParseInt32(grstr);
    }

    if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
       return NULL;
    }
    Char32 sign = id.GetChar(3);
    Int32 raw = (hour * 3600000) + (minute * 60000);
    if (sign == '-') {
       raw = -raw;
    }

    String cleanId("");
    cleanId.AppendFormat("GMT%c%02d:%02d", sign, hour, minute);
    AutoPtr<ITimeZone> tz;
    CSimpleTimeZone::New(raw, cleanId , (ITimeZone **)&tz);
    return tz;
}
Example #10
0
void MultipleChoiceValue::normalForm() {
	String val = value->toString();
	// which choices are active?
	vector<bool> seen(field().choices->lastId());
	for (size_t pos = 0 ; pos < val.size() ; ) {
		if (val.GetChar(pos) == _(' ')) {
			++pos; // ingore whitespace
		} else {
			// does this choice match the one asked about?
			size_t end = val.find_first_of(_(','), pos);
			if (end == String::npos) end = val.size();
			// find this choice
			for (size_t i = 0 ; i < seen.size() ; ++i) {
				if (is_substr(val, pos, field().choices->choiceName((int)i))) {
					seen[i] = true;
					break;
				}
			}
			pos = end + 1;
		}
	}
	// now put them back in the right order
	val.clear();
	for (size_t i = 0 ; i < seen.size() ; ++i) {
		if (seen[i]) {
			if (!val.empty()) val += _(", ");
			val += field().choices->choiceName((int)i);
		}
	}
	// empty choice name
	if (val.empty()) {
		val = field().empty_choice;
	}
	// store
	value = with_defaultness_of(value, to_script(val));
}
Example #11
0
ECode CURI::ParseAuthority(
    /* [in] */ Boolean forceServer)
{
    if (mAuthority.IsNull()) {
        return NOERROR;
    }

    String tempUserInfo;
    String temp = mAuthority;
    Int32 index = temp.IndexOf('@');
    Int32 hostIndex = 0;
    if (index != -1) {
        // remove user info
        tempUserInfo = temp.Substring(0, index);
        FAIL_RETURN(ValidateUserInfo(mAuthority, tempUserInfo, 0));
        temp = temp.Substring(index + 1); // host[:port] is left
        hostIndex = index + 1;
    }

    index = temp.LastIndexOf(':');
    Int32 endIndex = temp.IndexOf(']');

    String tempHost;
    Int32 tempPort = -1;
    if (index != -1 && endIndex < index) {
        // determine port and host
        tempHost = temp.Substring(0, index);

        Char32 firstPortChar = temp.GetChar(index + 1);
        if (firstPortChar >= '0' && firstPortChar <= '9') {
            // allow only digits, no signs
            ECode ec = StringUtils::Parse(temp.Substring(index + 1), &tempPort);
            if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) {
                if (forceServer) {
                    ALOGE("%s Invalid port number %d", mAuthority.string(), hostIndex + index + 1);
                    return E_URI_SYNTAX_EXCEPTION;
                }
                return NOERROR;
            }
        } else {
            if (forceServer) {
                ALOGE("%s Invalid port number %d", mAuthority.string(), hostIndex + index + 1);
                return E_URI_SYNTAX_EXCEPTION;
            }
            return NOERROR;
        }
    }
    else {
        tempHost = temp;
    }

    if (tempHost.IsEmpty()) {
        if (forceServer) {
            return E_URI_SYNTAX_EXCEPTION;
        }
        return NOERROR;
    }

    Boolean isValid = FALSE;
    FAIL_RETURN(IsValidHost(forceServer, tempHost, &isValid));
    if (!isValid) {
        return NOERROR;
    }

    // this is a server based uri,
    // fill in the userInfo, host and port fields
    mUserInfo = tempUserInfo;
    mHost = tempHost;
    mPort = tempPort;
    mServerAuthority = TRUE;

    return NOERROR;
}