void Strings::setText(const char* value) { AutoUpdater autoUpdater(*this); std::string valueStr(value); std::string lineBreak = getLineBreak(); int start = 0; clear(); while (true) { std::string::size_type pos = valueStr.find(lineBreak, start); if (pos != std::string::npos) { add(valueStr.substr(start, pos - start).c_str()); start = (int)(pos + lineBreak.length()); } else { std::string str = valueStr.substr(start); if (!str.empty()) add(str.c_str()); break; } } }
void BitmapEncoder::addValPos(ValPos* vp_){ map<string, byte*>::iterator p_it; map<string, PosBlock*>::iterator b_it; string valueStr( reinterpret_cast<char const*>(vp_->value), vp_->getSize()); b_it=blockMap.find(valueStr); if(b_it == blockMap.end()){//Current vp_ doesn't exist in the block map initANewBlock(valueStr, vp_);//Initiate a new block }else{//vp_ block is exisiting if (!blockMap[valueStr]->addPosition(vp_->position)){//block is full /*Try to append the block to corresponding page. First check whether there is existing page. If no, create one*/ p_it=pageMap.find(valueStr); if(p_it == pageMap.end())initANewPage(valueStr); if(!appendBlocktoPage(pageMap[valueStr], blockMap[valueStr])) {//page is full putPage2Queue(pageMap[valueStr],valueStr); pageMap.erase(p_it); initANewPage(valueStr); appendBlocktoPage(pageMap[valueStr], blockMap[valueStr]);//Shoud be true } blockMap.erase(valueStr);//Erase the block in map initANewBlock(valueStr, vp_);//Initate a new one } } }
void WebURLResponse::addHTTPHeaderField(const WebString& name, const WebString& value) { // FIXME: Add an addHTTPHeaderField method to ResourceResponse. const HTTPHeaderMap& map = m_private->m_resourceResponse->httpHeaderFields(); String valueStr(value); pair<HTTPHeaderMap::iterator, bool> result = const_cast<HTTPHeaderMap*>(&map)->add(name, valueStr); if (!result.second) result.first->second += ", " + valueStr; }
TEST(RuleSetTest, findBestRuleSetAndAdd_DivWithContent) { CSSTestHelper helper; helper.addCSSRules("div::content { }"); RuleSet& ruleSet = helper.ruleSet(); AtomicString str("div"); const TerminatedArray<RuleData>* rules = ruleSet.tagRules(str); ASSERT_EQ(1u, rules->size()); AtomicString valueStr("content"); ASSERT_EQ(valueStr, rules->at(0).selector().tagHistory()->value()); }
/*! Implementation for traverse so always true. */ bool SdFixture::execute(void * objectInstance, QString actionName, QHash<QString, QString> parameters, QString & stdOut) { debug("SdFixture::execute"); bool returnValue = true; #ifdef Q_OS_SYMBIAN const TUid fixtureUid = TUid::Uid(0x20026F7E); THashFunction32<RBuf8> hashFunc( RBufHashFunction ); TIdentityRelation<RBuf8> idFunc( RBufIdentityFunction ); RHashMap<RBuf8, RBuf8> paramPairs( hashFunc, idFunc ); CleanupClosePushL( paramPairs ); debug("SdFixture::execute read params"); QHashIterator<QString, QString> i(parameters); while (i.hasNext()) { i.next(); if(!i.key().isEmpty() && !i.value().isEmpty() && i.key() != OBJECT_TYPE){ debug("parametrit: " + i.key()+";"+ i.value()); debug("SdFixture::execute read key"); RBuf8 keyBuf; RBuf8 valueBuf; TPtrC16 keyStr(reinterpret_cast<const TUint16*>(i.key().utf16())); TPtrC16 valueStr(reinterpret_cast<const TUint16*>(i.value().utf16())); keyBuf.Create(keyStr.Length()); valueBuf.Create(valueStr.Length()); keyBuf.Copy(keyStr); valueBuf.Copy(valueStr); debug("SdFixture::execute insert to hash"); paramPairs.InsertL( keyBuf, valueBuf ); debug("SdFixture::execute pop hbufs"); } } debug("SdFixture::execute make fixture"); CTasFixturePluginInterface* fixture = CTasFixturePluginInterface::NewL( fixtureUid ); CleanupStack::PushL( fixture ); debug("SdFixture::execute conver actionname"); TPtrC16 actionStr(reinterpret_cast<const TUint16*>(actionName.utf16())); RBuf8 actionBuf; actionBuf.Create(actionStr.Length()); CleanupClosePushL( actionBuf ); actionBuf.Copy(actionStr); debug("SdFixture::execute execute fixture"); RBuf8 response; CleanupClosePushL( response ); if(fixture->Execute( NULL, actionBuf, paramPairs, response ) != KErrNone){ returnValue = false; } debug("SdFixture::execute convert response"); stdOut = XQConversions::s60Desc8ToQString(response); CleanupStack::PopAndDestroy( 4 );//response, fixture, paramPairs #endif debug("SdFixture::execute done"); return returnValue; }
int main(int argc, char* argv[]) { if (argc < 2) { MAX_COUNTS = 5000000; } else { std::string valueStr(argv[1]); bool has_only_digits = (valueStr.find_first_not_of( "0123456789" ) == std::string::npos); if (has_only_digits) { std::istringstream aStream(valueStr); aStream >> MAX_COUNTS; } else { std::cerr << "Argument should be an integer\n"; return 1; } }
void Strings::setValue(int index, const char* value) { std::string valueStr(value); if (valueStr.empty()) { if (index >= 0) del(index); } else { if (index < 0) index = add(""); setString(index, (getName(index) + getNameValueSeparator() + valueStr).c_str()); } }
int Lane::onHeader(const nghttp2_frame *frame, const std::uint8_t *name, std::size_t namelen, const std::uint8_t *value, std::size_t valuelen, std::uint8_t flags) { bool noIndex(flags & NGHTTP2_NV_FLAG_NO_INDEX); std::string nameStr(reinterpret_cast<const char*>(name), namelen); std::string valueStr(reinterpret_cast<const char*>(value), valuelen); parseHeader(nameStr, valueStr); _headers.emplace(std::make_pair(std::move(nameStr), header_value{std::move(valueStr), noIndex})); return 0; }
void Strings::setValue(const char* name, const char* value) { std::string nameStr(name); std::string valueStr(value); int i = indexOfName(nameStr.c_str()); if (valueStr.empty()) { if (i >= 0) del(i); } else { if (i < 0) i = add(""); setString(i, (nameStr + getNameValueSeparator() + valueStr).c_str()); } }
int c_zht_insert2(const char *key, const char *value) { string keyStr(key); string valueStr(value); if (keyStr.empty()) //empty key not allowed. return -1; Package package; package.set_virtualpath(keyStr); //as key package.set_isdir(true); package.set_replicano(5); package.set_operation(3); //1 for look up, 2 for remove, 3 for insert if (!valueStr.empty()) package.set_realfullpath(valueStr); return zhtClient.insert(package.SerializeAsString()); }
int GenericAttributeText::Compare(WidgetAttributeText& attr, BPoseView*) { GenericAttributeText* compareTo = dynamic_cast<GenericAttributeText*>(&attr); ThrowOnAssert(compareTo != NULL); if (fValueDirty) ReadValue(&fFullValueText); if (compareTo->fValueDirty) compareTo->ReadValue(&compareTo->fFullValueText); // sort undefined values last, regardless of the other value if (!fValueIsDefined) return compareTo->fValueIsDefined ? 1 : 0; if (!compareTo->fValueIsDefined) return -1; switch (fColumn->AttrType()) { case B_STRING_TYPE: return fFullValueText.ICompare(compareTo->fFullValueText); case B_CHAR_TYPE: { char vStr[2] = { static_cast<char>(fValue.uint8t), 0 }; char cStr[2] = { static_cast<char>(compareTo->fValue.uint8t), 0}; BString valueStr(vStr); BString compareToStr(cStr); return valueStr.ICompare(compareToStr); } case B_FLOAT_TYPE: return fValue.floatt >= compareTo->fValue.floatt ? (fValue.floatt == compareTo->fValue.floatt ? 0 : 1) : -1; case B_DOUBLE_TYPE: return fValue.doublet >= compareTo->fValue.doublet ? (fValue.doublet == compareTo->fValue.doublet ? 0 : 1) : -1; case B_BOOL_TYPE: return fValue.boolt >= compareTo->fValue.boolt ? (fValue.boolt == compareTo->fValue.boolt ? 0 : 1) : -1; case B_UINT8_TYPE: return fValue.uint8t >= compareTo->fValue.uint8t ? (fValue.uint8t == compareTo->fValue.uint8t ? 0 : 1) : -1; case B_INT8_TYPE: return fValue.int8t >= compareTo->fValue.int8t ? (fValue.int8t == compareTo->fValue.int8t ? 0 : 1) : -1; case B_UINT16_TYPE: return fValue.uint16t >= compareTo->fValue.uint16t ? (fValue.uint16t == compareTo->fValue.uint16t ? 0 : 1) : -1; case B_INT16_TYPE: return fValue.int16t >= compareTo->fValue.int16t ? (fValue.int16t == compareTo->fValue.int16t ? 0 : 1) : -1; case B_UINT32_TYPE: return fValue.uint32t >= compareTo->fValue.uint32t ? (fValue.uint32t == compareTo->fValue.uint32t ? 0 : 1) : -1; case B_TIME_TYPE: // time_t typedef'd to a long, i.e. a int32 case B_INT32_TYPE: return fValue.int32t >= compareTo->fValue.int32t ? (fValue.int32t == compareTo->fValue.int32t ? 0 : 1) : -1; case B_OFF_T_TYPE: // off_t typedef'd to a long long, i.e. a int64 case B_INT64_TYPE: return fValue.int64t >= compareTo->fValue.int64t ? (fValue.int64t == compareTo->fValue.int64t ? 0 : 1) : -1; case B_UINT64_TYPE: default: return fValue.uint64t >= compareTo->fValue.uint64t ? (fValue.uint64t == compareTo->fValue.uint64t ? 0 : 1) : -1; } return 0; }
JBoolean JRecurseFunction ( const JCharacter* origExpr, const JSize origLength, const JVariableList* theVariableList, JFunction** theFunction, const JBoolean allowUIF ) { *theFunction = NULL; // remove enclosing parentheses const JCharacter* expr = origExpr; const JSize length = JStripParentheses(&expr, origLength); if (length == 0) { (JGetUserNotification())->ReportError("You specified an empty function"); return kJFalse; } // check for summation (+,-) JParseResult result = JParseAsSummation(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for product before division // so we correctly parse x/y*z as (x/y)*z result = JParseAsProduct(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for division result = JParseAsDivision(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for exponentiation result = JParseAsExponentiation(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for standard function result = JParseAsFunctionWithArgs(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for function of discrete variable result = JParseAsFunctionOfDiscrete(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for named constant if (JIsNamedConstant(expr, length, theFunction)) { return kJTrue; } // check for variable name result = JParseAsNumericVariable(expr, length, theVariableList, theFunction, allowUIF); if (result == kJParsedOK) { return kJTrue; } else if (result == kJParseError) { return kJFalse; } // check for empty JUserInputFunction if (allowUIF && JStringsEqual(expr, length, JUserInputFunction::GetEmptyString())) { *theFunction = new JUserInputFunction(theVariableList, JGetCurrFontManager(), JGetCurrColormap()); assert( *theFunction != NULL ); return kJTrue; } // check for constant, must occupy entire string JString valueStr(expr, length); JBoolean isPercentage = kJFalse; if (valueStr.GetLastCharacter() == '%') { isPercentage = kJTrue; valueStr.RemoveSubstring(valueStr.GetLength(), valueStr.GetLength()); valueStr.TrimWhitespace(); } JFloat value; if (valueStr.ConvertToFloat(&value)) { if (isPercentage) { value /= 100.0; } *theFunction = new JConstantValue(value); assert( *theFunction != NULL ); return kJTrue; } else if (jerrno() == ERANGE) { JString errorStr(expr, length); errorStr.Prepend("\""); errorStr += "\" is too large to be represented."; (JGetUserNotification())->ReportError(errorStr); return kJFalse; } // this string is not a function JString errorStr(expr, length); errorStr.Prepend("\""); errorStr += "\" is not a valid function."; (JGetUserNotification())->ReportError(errorStr); return kJFalse; }
bool SkMemberInfo::setValue(SkAnimateMaker& maker, SkTDOperandArray* arrayStorage, int storageOffset, int maxStorage, SkDisplayable* displayable, SkDisplayTypes outType, const char rawValue[], size_t rawValueLen) const { SkString valueStr(rawValue, rawValueLen); SkScriptValue scriptValue; scriptValue.fType = SkType_Unknown; scriptValue.fOperand.fS32 = 0; SkDisplayTypes type = getType(); SkAnimatorScript engine(maker, displayable, type); if (arrayStorage) displayable = NULL; bool success = true; void* untypedStorage = NULL; if (displayable && fType != SkType_MemberProperty && fType != SkType_MemberFunction) untypedStorage = (SkTDOperandArray*) memberData(displayable); if (type == SkType_ARGB) { // for both SpiderMonkey and SkiaScript, substitute any #xyz or #xxyyzz first // it's enough to expand the colors into 0xFFxxyyzz const char* poundPos; while ((poundPos = strchr(valueStr.c_str(), '#')) != NULL) { size_t offset = poundPos - valueStr.c_str(); if (valueStr.size() - offset < 4) break; char r = poundPos[1]; char g = poundPos[2]; char b = poundPos[3]; if (is_hex(r) == false || is_hex(g) == false || is_hex(b) == false) break; char hex = poundPos[4]; if (is_hex(hex) == false) { valueStr.insertUnichar(offset + 1, r); valueStr.insertUnichar(offset + 3, g); valueStr.insertUnichar(offset + 5, b); } *(char*) poundPos = '0'; // overwrite '#' valueStr.insert(offset + 1, "xFF"); } } if (SkDisplayType::IsDisplayable(&maker, type) || SkDisplayType::IsEnum(&maker, type) || type == SkType_ARGB) goto scriptCommon; switch (type) { case SkType_String: #if 0 if (displayable && displayable->isAnimate()) { goto noScriptString; } if (strncmp(rawValue, "#string:", sizeof("#string:") - 1) == 0) { SkASSERT(sizeof("string") == sizeof("script")); char* stringHeader = valueStr.writable_str(); memcpy(&stringHeader[1], "script", sizeof("script") - 1); rawValue = valueStr.c_str(); goto noScriptString; } else #endif if (strncmp(rawValue, "#script:", sizeof("#script:") - 1) != 0) goto noScriptString; valueStr.remove(0, 8); case SkType_Unknown: case SkType_Int: case SkType_MSec: // for the purposes of script, MSec is treated as a Scalar case SkType_Point: case SkType_3D_Point: case SkType_Float: case SkType_Array: scriptCommon: { const char* script = valueStr.c_str(); success = engine.evaluateScript(&script, &scriptValue); if (success == false) { maker.setScriptError(engine); return false; } } SkASSERT(success); if (scriptValue.fType == SkType_Displayable) { if (type == SkType_String) { const char* charPtr; maker.findKey(scriptValue.fOperand.fDisplayable, &charPtr); scriptValue.fOperand.fString = new SkString(charPtr); scriptValue.fType = SkType_String; engine.SkScriptEngine::track(scriptValue.fOperand.fString); break; } SkASSERT(SkDisplayType::IsDisplayable(&maker, type)); if (displayable) displayable->setReference(this, scriptValue.fOperand.fDisplayable); else arrayStorage->begin()[0].fDisplayable = scriptValue.fOperand.fDisplayable; return true; } if (type != scriptValue.fType) { if (scriptValue.fType == SkType_Array) { engine.forget(scriptValue.getArray()); goto writeStruct; // real structs have already been written by script } switch (type) { case SkType_String: success = engine.convertTo(SkType_String, &scriptValue); break; case SkType_MSec: case SkType_Float: success = engine.convertTo(SkType_Float, &scriptValue); break; case SkType_Int: success = engine.convertTo(SkType_Int, &scriptValue); break; case SkType_Array: success = engine.convertTo(arrayType(), &scriptValue); // !!! incomplete; create array of appropriate type and add scriptValue to it SkASSERT(0); break; case SkType_Displayable: case SkType_Drawable: return false; // no way to convert other types to this default: // to avoid warnings break; } if (success == false) return false; } if (type == SkType_MSec) scriptValue.fOperand.fMSec = SkScalarMulRound(scriptValue.fOperand.fScalar, 1000); scriptValue.fType = type; break; noScriptString: case SkType_DynamicString: if (fType == SkType_MemberProperty && displayable) { SkString string(rawValue, rawValueLen); SkScriptValue scriptValue; scriptValue.fOperand.fString = &string; scriptValue.fType = SkType_String; displayable->setProperty(propertyIndex(), scriptValue); } else if (displayable) { SkString* string = (SkString*) memberData(displayable); string->set(rawValue, rawValueLen); } else { SkASSERT(arrayStorage->count() == 1); arrayStorage->begin()->fString->set(rawValue, rawValueLen); } goto dirty; case SkType_Base64: { SkBase64 base64; base64.decode(rawValue, rawValueLen); *(SkBase64* ) untypedStorage = base64; } goto dirty; default: SkASSERT(0); break; } // if (SkDisplayType::IsStruct(type) == false) { writeStruct: if (writeValue(displayable, arrayStorage, storageOffset, maxStorage, untypedStorage, outType, scriptValue)) { maker.setErrorCode(SkDisplayXMLParserError::kUnexpectedType); return false; } } dirty: if (displayable) displayable->dirty(); return true; }
am_status_t LogService::addLogDetails(const std::string& logName, const LogRecord& record, const std::string& loggedByTokenID) { ScopeLock scopeLock(mLock); char logLevel[32]; am_status_t status = AM_SUCCESS; char *msg = NULL; std::string message = record.getLogMessage(); //The encoded log message needs to be in multiple of 4 bytes. msg = (char *)malloc(((message.size() * 4/3 + 1)/4+1)*4 + 4); if(msg != NULL) { encode_base64(message.c_str(), message.size(), msg); } else { status = AM_NO_MEMORY; } if (status == AM_SUCCESS) { if(!remoteBodyChunkListInitialized) { const std::size_t NUM_EXTRA_CHUNKS = 50; remoteRequest = new Request(*this, requestPrefixChunk, logRequestPrefixChunk, NUM_EXTRA_CHUNKS); if (remoteRequest != NULL) { remoteBodyChunkList = remoteRequest->getBodyChunkList(); remoteBodyChunkListInitialized = true; } } if(bufferCount >= 1) { remoteBodyChunkList.push_back(additionalRequestPrefixChunk); BodyChunk temp; char serviceIdBuf[1024]; if (remoteRequest != NULL) { remoteRequest->getNextServiceRequestIdAsString( serviceIdBuf, sizeof(serviceIdBuf)); } temp.data = serviceIdBuf; remoteBodyChunkList.push_back(temp); } sprintf(logLevel, "%d", record.getLogLevel()); remoteBodyChunkList.push_back(logLogPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(logName)); remoteBodyChunkList.push_back(logSidPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(loggedByTokenID)); remoteBodyChunkList.push_back(logLogSuffixChunk); remoteBodyChunkList.push_back(logRecordPrefixChunk); remoteBodyChunkList.push_back(logLevelPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(std::string(logLevel))); remoteBodyChunkList.push_back(logLevelSuffixChunk); remoteBodyChunkList.push_back(logRecMsgPrefixChunk); std::string t_mesg(msg); free(msg); Utils::expandEntityRefs(t_mesg); remoteBodyChunkList.push_back(BodyChunk(t_mesg)); remoteBodyChunkList.push_back(logRecMsgSuffixChunk); remoteBodyChunkList.push_back(logInfoMapPrefixChunk); const Properties &properties = record.getLogInfo(); Properties::const_iterator iter = properties.begin(); for(; iter != properties.end(); iter++) { const Properties::key_type &k_iter = iter->first; const Properties::mapped_type &v_iter = iter->second; std::string keyStr(""); keyStr = k_iter.c_str(); std::string valueStr(""); valueStr = v_iter.c_str(); remoteBodyChunkList.push_back(logInfoKeyPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(keyStr)); remoteBodyChunkList.push_back(logInfoKeySuffixChunk); remoteBodyChunkList.push_back(logInfoValuePrefixChunk); remoteBodyChunkList.push_back(BodyChunk(valueStr)); remoteBodyChunkList.push_back(logInfoValueSuffixChunk); } remoteBodyChunkList.push_back(logInfoMapSuffixChunk); remoteBodyChunkList.push_back(logRecordSuffixChunk); remoteBodyChunkList.push_back(requestSuffixChunk); bufferCount++; } else { status = AM_NO_MEMORY; } return status; }