sp<Short> Short::valueOf(const sp<String>& string, int32_t radix) { if (string == nullptr || string->isEmpty()) { throw NumberFormatException("String is null or empty"); } if (::isspace(string->charAt(0))) { throw NumberFormatException(String::format("Invalid integral value: %s", string->c_str())); } // See http://man7.org/linux/man-pages/man3/strtol.3.html. char* endptr; int16_t value = ::strtol(string->c_str(), &endptr, radix); if (*endptr != '\0') { throw NumberFormatException(String::format("Invalid integral value: %s", string->c_str())); } return new Short(value); }
Process::Process(const sp<String>& name) : mName(name), mLock(new ReentrantLock()), mCondition(mLock->newCondition()) { mMainThread = new HandlerThread(String::format("Process {%s}", name->c_str())); mServices = new HashMap<sp<ComponentName>, sp<Service>>(); }
void FileHandler::Writer::write(const sp<String>& s, uint32_t offset, size_t length) { const ssize_t size = ::write(mFd, s->c_str() + offset, length); if (size > 0) { mSize += size; } }
void Eliza::processConfigurationRule(sp<String> s) { sp<StringArray> lines = new StringArray(4); if (Strings::match(s, "*reasmb: *", lines)) { if (reassemblyList == nullptr) { printf("Error: no reassembly list\n"); return; } reassemblyList->add(lines->get(1)); } else if (Strings::match(s, "*decomp: *", lines)) { if (decompositionList == nullptr) { printf("Error: no decomposition list\n"); return; } reassemblyList = new ReassemblyList(); sp<String> tmp = lines->get(1); if (Strings::match(tmp, "$ *", lines)) { decompositionList->add(lines->get(0), true, reassemblyList); } else { decompositionList->add(tmp, false, reassemblyList); } } else if (Strings::match(s, "*key: * #*", lines)) { decompositionList = new DecompositionList(); reassemblyList = nullptr; int n = 0; if (lines->get(2)->length() != 0) { try { n = Integer::valueOf(lines->get(2))->intValue(); } catch (const NumberFormatException& e) { printf("Number is wrong in key: %s\n", lines->get(2)->c_str()); } } keys->add(lines->get(1), n, decompositionList); } else if (Strings::match(s, "*key: *", lines)) { decompositionList = new DecompositionList(); reassemblyList = nullptr; keys->add(lines->get(1), 0, decompositionList); } else if (Strings::match(s, "*synon: * *", lines)) { sp<WordList> words = new WordList(); words->add(lines->get(1)); s = lines->get(2); while (Strings::match(s, "* *", lines)) { words->add(lines->get(0)); s = lines->get(1); } words->add(s); synonyms->add(words); } else if (Strings::match(s, "*pre: * *", lines)) { preList->add(lines->get(1), lines->get(2)); } else if (Strings::match(s, "*post: * *", lines)) { postList->add(lines->get(1), lines->get(2)); } else if (Strings::match(s, "*initial: *", lines)) { welcome = lines->get(1); } else if (Strings::match(s, "*final: *", lines)) { goodbye = lines->get(1); } else if (Strings::match(s, "*quit: *", lines)) { quit->add(String::format(" %s ", lines->get(1)->c_str())); } else { printf("Unrecognized input: %s\n", s->c_str()); } }
sp<Double> Double::valueOf(const sp<String>& s) { return valueOf(s->c_str()); }
void Bundle::putString(const char* key, const sp<String>& string) { putString(key, (string != NULL) ? string->c_str() : NULL); }
sp<ArrayList<sp<String>>> String::split(const sp<String>& separator) const { return split(separator->c_str()); }
ssize_t String::indexOf(const sp<String>& string, size_t fromIndex) const { return indexOf(string->c_str() + fromIndex); }
ssize_t String::indexOf(const sp<String>& string) const { return indexOf(string->c_str()); }
bool String::endsWith(const sp<String>& suffix) const { return endsWith(suffix->c_str()); }
bool String::startsWith(const sp<String>& prefix) const { return startsWith(prefix->c_str()); }
bool String::contains(const sp<String>& subString) const { return contains(subString->c_str()); }
sp<File> ContextImpl::makeFilename(const sp<File>& baseDir, const sp<String>& name) { if (name->indexOf(File::separatorChar) < 0) { return new File(baseDir, name); } throw IllegalArgumentException(String::format("File %s contains a path separator", name->c_str())); }