Boolean CUsbManager::PropertyContainsFunction( /* [in] */ const String& property, /* [in] */ const String& function) { AutoPtr<ISystemProperties> sp; CSystemProperties::AcquireSingleton((ISystemProperties**)&sp); String functions; sp->Get(property, String(""), &functions); Int32 index = functions.IndexOf(function); if (index < 0) { return FALSE; } Char32 c1 = functions.GetChar(index - 1); if (index > 0 && c1 != ',') { return FALSE; } Int32 charAfter = index + function.GetLength(); Char32 c2 = functions.GetChar(charAfter); if (charAfter < (Int32)functions.GetLength() && c2 != ',') { return FALSE; } return TRUE; }
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; }
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; }
String CHttpAuthHeader::TrimDoubleQuotesIfAny( /* [in] */ const String& value) { if (value != NULL) { Int32 len = value.GetLength(); if (len > 2 && value.GetChar(0) == '\"' && value.GetChar(len -1) == '\"') { return value.Substring(1, len - 1); } } return value; }
String File::Join( /* [in] */ const String& prefix, /* [in] */ const String& suffix) { Int32 prefixLength = prefix.GetLength(); Boolean haveSlash = (prefixLength > 0 && prefix.GetChar(prefixLength - 1) == sSeparatorChar); if (!haveSlash) { haveSlash = (suffix.GetLength() > 0 && suffix.GetChar(0) == sSeparatorChar); } String joinStr = prefix; if (!haveSlash) joinStr.AppendFormat("%c", sSeparatorChar); joinStr += suffix; return joinStr; }
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; }
ECode CEmojiFactory::GetAndroidPuaFromVendorSpecificPua( /* [in] */ const String& vspString, /* [out] */ String* retValue) { VALIDATE_NOT_NULL(retValue); *retValue = NULL; if (vspString.IsNull()) { return E_NULL_POINTER_EXCEPTION; } Int32 minVsp = NativeGetMinimumVendorSpecificPua(mNativeEmojiFactory); Int32 maxVsp = NativeGetMaximumVendorSpecificPua(mNativeEmojiFactory); AutoPtr<ArrayOf<Int32> > codePoints = ArrayOf<Int32>::Alloc(vspString.GetCharCount(0, len));\ Int32 new_len = 0; for (Int32 i=0; i < len; i++,new_len++) Int32 codePoint = (Int32)vspString.GetChar(i); if (minVsp <= codePoint && codePoint <= maxVsp) { Int32 newCodePoint = GetAndroidPuaFromVendorSpecificPua(codePoint); if (newCodePoint > 0) { (*codePoints)[new_len] = newCodePoint; continue; } } (*codePoints)[new_len] = codePoint; }
/** * Return the next command line option. This has a number of special cases * which closely, but not exactly, follow the POSIX command line options * patterns: * * <pre> * -- means to stop processing additional options * -z means option z * -z ARGS means option z with (non-optional) arguments ARGS * -zARGS means option z with (optional) arguments ARGS * --zz means option zz * --zz ARGS means option zz with (non-optional) arguments ARGS * </pre> * * Note that you cannot combine single letter options; -abc != -a -b -c * * @return Returns the option string, or null if there are no more options. */ String Monkey::NextOption() { if (mNextArg >= mArgs->GetLength()) { return String(); } String arg = (*mArgs)[mNextArg]; if (!arg.StartWith("-")) { return String(); } mNextArg++; if (arg.Equals("--")) { return String(); } if (arg.GetLength() > 1 && arg.GetChar(1) != '-') { if (arg.GetLength() > 2) { mCurArgData = arg.Substring(2); return arg.Substring(0, 2); } else { mCurArgData = String(); return arg; } } mCurArgData = String(); return arg; }
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); } }
ECode CAuthorityEntry::constructor( /* [in] */ const String& host, /* [in] */ const String& port) { mOrigHost = host; mWild = host.GetLength() > 0 && host.GetChar(0) == '*'; mHost = mWild ? host.Substring(1)/*.intern()*/ : host; mPort = !port.IsNull() ? port.ToInt32() : -1; return NOERROR; }
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; }
void ApprExpansionDatabase::doWrite(wxOutputStream& out) { wxTextOutputStream tout(out, wxEOL_DOS); // write in order first FOR_EACH(c, order) { String code = c; if (code.GetChar(0) != _('-')) { // but not the rarities tout << code << _("-") << expansions[c] << _("\n"); expansions.erase(c); } }
ECode CQName::ValueOf( /* [in] */ String qNameAsString, /* [out] */ IQName** qName) { // null is not valid if (qNameAsString == NULL) { // throw new IllegalArgumentException("cannot create QName from \"null\" or \"\" String"); return E_ILLEGAL_ARGUMENT_EXCEPTION; } // "" local part is valid to preserve compatible behavior with QName 1.0 if (qNameAsString.GetLength() == 0) { return CQName::New( IXMLConstants::NULL_NS_URI, qNameAsString, IXMLConstants::DEFAULT_NS_PREFIX, qName); } // local part only? if (qNameAsString.GetChar(0) != '{') { return CQName::New( IXMLConstants::NULL_NS_URI, qNameAsString, IXMLConstants::DEFAULT_NS_PREFIX, qName); } // Namespace URI improperly specified? if (qNameAsString.StartWith(String("{") + IXMLConstants::NULL_NS_URI + "}")) { // throw new IllegalArgumentException( // "Namespace URI .equals(XMLConstants.NULL_NS_URI), " // + ".equals(\"" + XMLConstants.NULL_NS_URI + "\"), " // + "only the local part, " // + "\"" + qNameAsString.substring(2 + XMLConstants.NULL_NS_URI.length()) + "\", " // + "should be provided."); return E_ILLEGAL_ARGUMENT_EXCEPTION; } // Namespace URI and local part specified Int32 endOfNamespaceURI = qNameAsString.IndexOf('}'); if (endOfNamespaceURI == -1) { return E_ILLEGAL_ARGUMENT_EXCEPTION; // throw new IllegalArgumentException( // "cannot create QName from \"" // + qNameAsString // + "\", missing closing \"}\""); } return CQName::New( qNameAsString.Substring(1, endOfNamespaceURI), qNameAsString.Substring(endOfNamespaceURI + 1), IXMLConstants::DEFAULT_NS_PREFIX, qName); }
ECode CRandomAccessFile::WriteBytes( /* [in] */ const String& str) { if (str.IsNullOrEmpty()) return NOERROR; AutoPtr<ArrayOf<Byte> > bytes = ArrayOf<Byte>::Alloc(str.GetLength()); for (Int32 index = 0; index < str.GetLength(); index++) { bytes->Set(index, (Byte)(str.GetChar(index) & 0xFF)); } return Write(bytes); }
ECode CFastXmlSerializer::WriteText( /* [in] */ const String& text) { if (mInTag) { FAIL_RETURN(Append('>')); mInTag = FALSE; } FAIL_RETURN(EscapeAndAppendString(text)); if (mIndent) { mLineStart = text.GetLength() > 0 && (text.GetChar(text.GetLength()-1) == '\n'); } return NOERROR; }
ECode DhcpPacket::AddTlv( /* [in] */ IByteBuffer* buf, /* [in] */ Byte type, /* [in] */ const String& str) { if (str != NULL) { buf->Put(type); buf->Put((Byte) str.GetLength()); for (Int32 i = 0; i < str.GetLength(); i++) { buf->Put((Byte) str.GetChar(i)); } } return NOERROR; }
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; }
String decodeUTF8BOM(const String& s) { #ifdef UNICODE if (!s.empty() && s.GetChar(0) == L'\xFEFF') { // skip byte-order-mark return s.substr(1); } else { return s; } #else wxWCharBuffer buf = s.wc_str(wxConvUTF8); if (buf && buf[size_t(0)] == L'\xFEFF') { // skip byte-order-mark return String(buf + 1, *wxConvCurrent); } else { return String(buf, *wxConvCurrent); } #endif }
String english_plural(const String& str) { if (str.size() > 2) { Char a = str.GetChar(str.size() - 2); Char b = str.GetChar(str.size() - 1); if (b == _('y') && is_constant(a)) { return str.substr(0, str.size() - 1) + _("ies"); } else if (b == _('o') && is_constant(a)) { return str + _("es"); } else if ((a == _('s') || a == _('c')) && b == _('h')) { return str + _("es"); } else if (b == _('s')) { return str + _("es"); } else { return str + _("s"); } } return str + _("s"); }
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; }
String FileUtils::BuildValidFatFilename( /* [in] */ const String& name) { if (name.IsEmpty() || name.Equals(String(".")) || name.Equals(String(".."))) { return String("(invalid)"); } Int32 length = name.GetLength(); StringBuilder res(length); for (Int32 i = 0; i < length; i++) { Char32 c = name.GetChar(i); if (IsValidFatFilenameChar(c)) { res.AppendChar(c); } else { res.AppendChar('_'); } } return res.ToString(); }
Boolean CLocaleBuilder::IsValidVariantSubtag( /* [in] */ const String& subTag) { // The BCP-47 spec states that : // - Subtags can be between [5, 8] alphanumeric chars in length. // - Subtags that start with a number are allowed to be 4 chars in length. if (subTag.GetLength() >= 5 && subTag.GetLength() <= 8) { if (CLocale::IsAsciiAlphaNum(subTag)) { return TRUE; } } else if (subTag.GetLength() == 4) { Char32 firstChar = subTag.GetChar(0); if ((firstChar >= '0' && firstChar <= '9') && CLocale::IsAsciiAlphaNum(subTag)) { return TRUE; } } return FALSE; }
String english_singular(const String& str) { if (str.size() > 3 && is_substr(str, str.size()-3, _("ies"))) { return str.substr(0, str.size() - 3) + _("y"); } else if (str.size() > 3 && is_substr(str, str.size()-3, _("oes"))) { return str.substr(0, str.size() - 2); } else if (str.size() > 4 && is_substr(str, str.size()-4, _("ches"))) { return str.substr(0, str.size() - 2); } else if (str.size() > 4 && is_substr(str, str.size()-4, _("shes"))) { return str.substr(0, str.size() - 2); } else if (str.size() > 4 && is_substr(str, str.size()-4, _("sses"))) { return str.substr(0, str.size() - 2); } else if (str.size() > 5 && is_substr(str, str.size()-3, _("ves")) && (is_substr(str, str.size()-5, _("el")) || is_substr(str, str.size()-5, _("ar")) )) { return str.substr(0, str.size() - 3) + _("f"); } else if (str.size() > 1 && str.GetChar(str.size() - 1) == _('s')) { return str.substr(0, str.size() - 1); } else if (str.size() >= 3 && is_substr(str, str.size()-3, _("men"))) { return str.substr(0, str.size() - 2) + _("an"); } else { return str; } }
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; }
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)); }
bool DropDownList::onCharInParent(wxKeyEvent& ev) { // keyboard codes int k = ev.GetKeyCode(); if (IsShown()) { if (open_sub_menu) { // sub menu always takes keys return open_sub_menu->onCharInParent(ev); } else { switch (k) { case WXK_UP: return selectItem(selected_item - 1); case WXK_DOWN: return selectItem(selected_item + 1); case WXK_RETURN: if (!showSubMenu() && (selected_item == NO_SELECTION || itemEnabled(selected_item))) { hide(true, false); // don't veto; always close } break; case WXK_SPACE: if (!showSubMenu() && (selected_item == NO_SELECTION || itemEnabled(selected_item))) { hide(true); } break; case WXK_ESCAPE: hide(false); break; case WXK_LEFT: if (parent_menu) hide(false); break; case WXK_RIGHT: return showSubMenu(); default: // match first character of an item, start searching just after the current selection size_t si = selected_item != NO_SELECTION ? selected_item + 1 : 0; size_t count = itemCount(); for (size_t i = 0 ; i < count ; ++i) { size_t index = (si + i) % count; if (!itemEnabled(index)) continue; String c = itemText(index); #ifdef UNICODE if (!c.empty() && toUpper(c.GetChar(0)) == toUpper(ev.GetUnicodeKey())) { #else if (!c.empty() && toUpper(c.GetChar(0)) == toUpper(ev.GetKeyCode())) { #endif // first character matches selected_item = index; showSubMenu(); selectItem(index); return true; } } } } return true; } else if (k==WXK_SPACE || k==WXK_RETURN || k==WXK_DOWN) { // drop down list is not shown yet, show it now show(false, wxPoint(0,0)); return true; } return false; }
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; }
// the remaing expansions (our new set) FOR_EACH(e, expansions) { String code = e.first; if (code.GetChar(0) != _('-')) { tout << code << _("-") << e.second << _("\n"); } }
// and at last the rarities FOR_EACH(c, order) { String code = c; if (code.GetChar(0) == _('-')) { tout << c << _("-") << expansions[c] << _("\n"); } }