Example #1
0
ECode CKXmlSerializer::WriteCdSect(
    /* [in] */ const String& text)
{
    FAIL_RETURN(Check(FALSE));
    // BEGIN android-changed: ]]> is not allowed within a CDATA,
    // so break and start a new one when necessary.
    String data;
    StringUtils::ReplaceAll(text, String("]]>"), String("]]]]><![CDATA[>"), &data);
    // We also aren't allowed any invalid characters.
    AutoPtr<ArrayOf<Char32> > charArray = data.GetChars();
    Char32 ch;
    Boolean valid;
    Int32 N = charArray->GetLength();
    for (Int32 i = 0; i < N; i++) {
        ch = (*charArray)[i];
        valid = (ch >= 0x20 && ch <= 0xd7ff) ||
            (ch == '\t' || ch == '\n' || ch == '\r') ||
            (ch >= 0xe000 && ch <= 0xfffd);
        if (!valid) {
            return ReportInvalidCharacter(ch);
        }
    }
    FAIL_RETURN(IWriter::Probe(mWriter)->Write(String("<![CDATA[")));
    FAIL_RETURN(IWriter::Probe(mWriter)->Write(data));
    return IWriter::Probe(mWriter)->Write(String("]]>"));
    // END android-changed
}
Example #2
0
Int32 UrlUtils::FindFirstOf(
    /* [in] */ const String& string,
    /* [in] */ const String& chars,
    /* [in] */ Int32 start,
    /* [in] */ Int32 end)
{
    AutoPtr<ArrayOf<Char32> > char32Array = string.GetChars();
    for (Int32 i = start; i < end; i++) {
        if (chars.IndexOf((*char32Array)[i]) != -1) {
            return i;
        }
    }
    return end;
}
Example #3
0
ECode CURI::ValidateUserInfo(
    /* [in] */ const String& uri,
    /* [in] */ const String& userInfo,
    /* [in] */ Int32 index)
{
    AutoPtr<ArrayOf<Char32> > char32Array = userInfo.GetChars();
    if (char32Array) {
        for (Int32 i = 0; i < char32Array->GetLength(); i++) {
            if ((*char32Array)[i] == ']' || (*char32Array)[i] == '[') {
                //            throw new URISyntaxException(uri, "Illegal character in userInfo", index + i);
                return E_URI_SYNTAX_EXCEPTION;
            }
        }
    }
    return NOERROR;
}
ECode CWifiInfo::RemoveDoubleQuotes(
    /* [in] */ const String& str,
    /* [out] */ String* value)
{
    VALIDATE_NOT_NULL(value);

    if (str.IsNull()) return NOERROR;
    AutoPtr<ArrayOf<Char32> > charArray = str.GetChars();
    const Int32 length = charArray->GetLength();
    if ((length > 1) && ((*charArray)[0] == '"') && ((*charArray)[length - 1] == '"')) {
        *value = str.Substring(1, length - 1);
        return NOERROR;
    }
    *value = str;
    return NOERROR;
}
Example #5
0
String UrlUtils::GetSchemePrefix(
    /* [in] */const String& spec)
{
    Int32 colon = spec.IndexOf(':');

    if (colon < 1) {
        return String(NULL);
    }

    AutoPtr<ArrayOf<Char32> > char32Array = spec.GetChars();
    for (int i = 0; i < colon; i++) {
        if (!IsValidSchemeChar(i, (Byte)(*char32Array)[i])) {
            return String(NULL);
        }
    }

    String result = spec.Substring(0, colon).ToLowerCase();
    return result;
}
Example #6
0
ECode CURI::ValidateScheme(
    /* [in] */ const String& uri,
    /* [in] */ Int32 end,
    /* [out] */ String* result)
{
    VALIDATE_NOT_NULL(result)
    *result = String(NULL);

    if (end == 0) {
        return E_URI_SYNTAX_EXCEPTION;
    }

    AutoPtr<ArrayOf<Char32> > char32Array = uri.GetChars();
    for (Int32 i = 0; i < end; i++) {
        if (!UrlUtils::IsValidSchemeChar(i, (*char32Array)[i])) {
            return E_URI_SYNTAX_EXCEPTION;
        }
    }
    *result = uri.Substring(0, end);
    return NOERROR;
}
Example #7
0
String Patterns::DigitsAndPlusOnly(
    /* [in] */ IMatcher* matcher)
{
    if (matcher == NULL) {
        return String(NULL);
    }

    StringBuilder buffer;
    String matchingRegion;
    matcher->Group(&matchingRegion);

    AutoPtr<ArrayOf<Char32> > charArray = matchingRegion.GetChars();
    Char32 character;
    for (UInt32 i = 0, size = charArray->GetLength(); i < size; i++) {
        character = (*charArray)[i];

        if (character == '+' || Character::IsDigit(character)) {
            buffer += character;
        }
    }
    return buffer.ToString();
}