void testStringWithFixedLen() { SString S; CreateString(S); PrintString(S); SString S2; CreateString(S2); PrintString(S2); SString T; StrConcat(T, S, S2); PrintString(T); SString Sub; SubString(Sub, T, 2, 3); PrintString(Sub); printf("compare two string:\n"); SString s1; CreateString(s1); PrintString(s1); SString s2; CreateString(s2); PrintString(s2); int result = StrCompare(s1, s2); if (!result) printf("s1 == s2"); else if (result > 0) printf("s1 > s2"); else printf("s1 < s2"); printf("\n"); }
void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* ctx_w) { NanScope(); if (returned_value->IsArray()) { Handle<Array> array = Handle<Array>::Cast(returned_value); ctx_w->imports = sass_make_import_list(array->Length()); for (size_t i = 0; i < array->Length(); ++i) { Local<Value> value = array->Get(i); if (!value->IsObject()) continue; Local<Object> object = Local<Object>::Cast(value); char* path = CreateString(object->Get(NanNew<String>("file"))); char* contents = CreateString(object->Get(NanNew<String>("contents"))); ctx_w->imports[i] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } } else if (returned_value->IsObject()) { ctx_w->imports = sass_make_import_list(1); Local<Object> object = Local<Object>::Cast(returned_value); char* path = CreateString(object->Get(NanNew<String>("file"))); char* contents = CreateString(object->Get(NanNew<String>("contents"))); ctx_w->imports[0] = sass_make_import_entry(path, (!contents || contents[0] == '\0') ? 0 : strdup(contents), 0); } else { ctx_w->imports = sass_make_import_list(1); ctx_w->imports[0] = sass_make_import_entry(ctx_w->file, 0, 0); } }
const char *FloatToString( Environment *theEnv, double number) { char floatString[40]; int i; char x; CLIPSLexeme *thePtr; gensprintf(floatString,"%.15g",number); for (i = 0; (x = floatString[i]) != '\0'; i++) { if ((x == '.') || (x == 'e')) { thePtr = CreateString(theEnv,floatString); return thePtr->contents; } } genstrcat(floatString,".0"); thePtr = CreateString(theEnv,floatString); return thePtr->contents; }
JSValue GlobalObject::requireModule(const JSObject& parent, const std::string& moduleId) { TITANIUM_GLOBALOBJECT_LOCK_GUARD; const auto js_context = parent.get_context(); // check if we have special module such as ti.map if (requiredBuiltinModuleExists(js_context, moduleId)) { return requireBuiltinModule(js_context, moduleId); } // check if we have native module if (requiredNativeModuleExists(js_context, moduleId)) { return requireNativeModule(js_context, moduleId); } auto module_path = requestResolveModule(parent, moduleId); if (module_path.empty()) { // Fall back to assuming equivalent of "/" + moduleId? module_path = requestResolveModule(parent, "/" + moduleId); if (module_path.empty()) { detail::ThrowRuntimeError("require", "Could not load module " + moduleId); } } // check if we have already loaded the module if (module_cache__.find(module_path) != module_cache__.end()) { return module_cache__.at(module_path); } const auto module_js = readRequiredModule(parent, module_path); if (module_js.empty()) { detail::ThrowRuntimeError("require", "Could not load module " + moduleId); } try { JSValue result = js_context.CreateUndefined(); if (boost::ends_with(module_path, ".json")){ result = js_context.CreateValueFromJSON(module_js); } else if (js_context.JSCheckScriptSyntax(module_js, moduleId)) { const std::vector<JSValue> args = { js_context.CreateString(moduleId), js_context.CreateString(module_js) }; result = require_function__(args, js_context.get_global_object()); } else { detail::ThrowRuntimeError("require", "Could not load module "+moduleId); } if (!result.IsObject()) { TITANIUM_LOG_WARN("GlobalObject::require: module '", moduleId, "' replaced 'exports' with a non-object: ", to_string(result)); } // cache it so that we can reuse it module_cache__.insert({module_path, result}); return result; } catch (const std::exception& exception) { detail::ThrowRuntimeError("require", "Error while require("+moduleId+") "+static_cast<std::string>(exception.what())); } catch (...) { detail::ThrowRuntimeError("require", "Unknown error while require("+moduleId+")"); } return js_context.CreateUndefined(); }
void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx_w, bool isFile, bool isSync) { NanScope(); struct Sass_Context* ctx; NanAssignPersistent(ctx_w->result, options->Get(NanNew("result"))->ToObject()); if (isFile) { ctx_w->fctx = (struct Sass_File_Context*) cptr; ctx = sass_file_context_get_context(ctx_w->fctx); } else { ctx_w->dctx = (struct Sass_Data_Context*) cptr; ctx = sass_data_context_get_context(ctx_w->dctx); } struct Sass_Options* sass_options = sass_context_get_options(ctx); ctx_w->importer_callback = NULL; ctx_w->is_sync = isSync; if (!isSync) { ctx_w->request.data = ctx_w; // async (callback) style Local<Function> success_callback = Local<Function>::Cast(options->Get(NanNew("success"))); Local<Function> error_callback = Local<Function>::Cast(options->Get(NanNew("error"))); ctx_w->success_callback = new NanCallback(success_callback); ctx_w->error_callback = new NanCallback(error_callback); } Local<Function> importer_callback = Local<Function>::Cast(options->Get(NanNew("importer"))); if (importer_callback->IsFunction()) { ctx_w->importer_callback = new NanCallback(importer_callback); uv_async_init(uv_default_loop(), &ctx_w->async, (uv_async_cb)dispatched_async_uv_callback); sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w)); } if(!isFile) { sass_option_set_input_path(sass_options, CreateString(options->Get(NanNew("file")))); } sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile")))); sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath")))); sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value()); sass_option_set_is_indented_syntax_src(sass_options, options->Get(NanNew("indentedSyntax"))->BooleanValue()); sass_option_set_source_comments(sass_options, options->Get(NanNew("comments"))->BooleanValue()); sass_option_set_omit_source_map_url(sass_options, options->Get(NanNew("omitSourceMapUrl"))->BooleanValue()); sass_option_set_source_map_embed(sass_options, options->Get(NanNew("sourceMapEmbed"))->BooleanValue()); sass_option_set_source_map_contents(sass_options, options->Get(NanNew("sourceMapContents"))->BooleanValue()); sass_option_set_source_map_file(sass_options, CreateString(options->Get(NanNew("sourceMap")))); sass_option_set_include_path(sass_options, CreateString(options->Get(NanNew("paths")))); sass_option_set_precision(sass_options, options->Get(NanNew("precision"))->Int32Value()); }
template<typename TComponent> inline TComponent getComponentOfEntity(TEntityId entityId) const { auto componentsOfEntity = entityComponentMap.find(entityId); if (componentsOfEntity == entityComponentMap.end()) throw EntityNotFoundException(CreateString(entityId, " does not exist in store")); auto componentName = GetNameOfComponent<TComponent>(); auto componentIt = componentsOfEntity->second.find(componentName); if (componentIt == componentsOfEntity->second.end()) throw ComponentNotFoundException(CreateString(componentName, " does not exist on ", entityId)); return *std::static_pointer_cast<TComponent>(componentIt->second); }
void V8IsolateImpl::EnableDebugging(int debugPort) { _ASSERTE(m_pIsolate == Isolate::GetCurrent()); _ASSERTE(Locker::IsLocked(m_pIsolate)); if (!m_DebuggingEnabled) { if (debugPort < 1) { debugPort = 9222; } auto wrThis = CreateWeakRef(); m_pDebugMessageDispatcher = CALLBACK_MANAGER(DebugMessageDispatcher)::Alloc([wrThis] { Concurrency::create_task([wrThis] { auto spIsolate = wrThis.GetTarget(); if (!spIsolate.IsEmpty()) { auto pIsolateImpl = static_cast<V8IsolateImpl*>(spIsolate.GetRawPtr()); pIsolateImpl->DispatchDebugMessages(); } }); }); _ASSERTE(m_pDebugMessageDispatcher); Debug::SetDebugMessageDispatchHandler(m_pDebugMessageDispatcher); ASSERT_EVAL(Debug::EnableAgent(*String::Utf8Value(CreateString(m_Name.c_str())), debugPort)); m_DebuggingEnabled = true; m_DebugPort = debugPort; } }
BOOL CALLBACK CStringSet::EnumResNameProc( HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam ) { CStringSet *set=(CStringSet*)lParam; // find resource HRSRC hr=FindResource(hModule,lpszName,RT_STRING); if (!hr) return TRUE; HGLOBAL hg=LoadResource(hModule,hr); if (hg) { const WORD *res=(WORD*)LockResource(hg); if (res) { for (int i=0;i<16;i++) { UINT id=(((int)lpszName)<<4)+i-16; CString str=CreateString(res); if (!str.IsEmpty()) (*set)[id]=str; res+=(*res)+1; } UnlockResource(hg); } } return TRUE; }
void CalculateInfoData() { int i,cn,crewQ; ref mchref,chref; crewQ = 0; mchref = GetMainCharacter(); for(i=0; i<4; i++) { cn = GetCompanionIndex(mchref,i); if( cn>=0 && GetRemovable(&Characters[cn]) ) { chref = GetCharacter(cn); crewQ += GetCrewQuantity(chref); } } int nLeaderShip = GetSummonSkillFromName(mchref,SKILL_LEADERSHIP); nPaymentQ = 5 + crewQ*(16-nLeaderShip); if( CheckAttribute(mchref,"CrewPayment") ) { nPaymentQ += makeint( stf(mchref.CrewPayment)*(11.0-SKILL_LEADERSHIP)/10.0 ); } nMoraleDecreaseQ = 30-nLeaderShip; if( CheckCharacterPerk(mchref,"IronWill") ) nMoraleDecreaseQ /= 2; CreateString(true,"payment",""+nPaymentQ,FONT_NORMAL,COLOR_NORMAL,320,258,SCRIPT_ALIGN_CENTER,1.0); if( sti(mchref.Money) < nPaymentQ ) { SetSelectable("B_OK",false); SetCurrentNode("B_CANCEL"); } }
ICCItem *CCodeChain::LookupGlobal (const CString &sGlobal, LPVOID pExternalCtx) // LookupGlobal // // Returns the binding for this item { CEvalContext EvalCtx; ICCItem *pItem; ICCItem *pResult; // Set up the context EvalCtx.pCC = this; EvalCtx.pLexicalSymbols = m_pGlobalSymbols; EvalCtx.pLocalSymbols = NULL; EvalCtx.pExternalCtx = pExternalCtx; // Create a variable pItem = CreateString(sGlobal); if (pItem->IsError()) return pItem; pResult = Lookup(&EvalCtx, pItem); pItem->Discard(this); return pResult; }
// fNextToken initially should point to // a string after the initial open paren ("(") // After this call, fNextToken points to the // first character after the matching close // paren. Only call AdvanceToNextToken() to get the NEXT // token after the one returned in fNextToken. void nsIMAPGenericParser::skip_to_close_paren() { int numberOfCloseParensNeeded = 1; while (ContinueParse()) { // go through fNextToken, account for nested parens const char *loc; for (loc = fNextToken; loc && *loc; loc++) { if (*loc == '(') numberOfCloseParensNeeded++; else if (*loc == ')') { numberOfCloseParensNeeded--; if (numberOfCloseParensNeeded == 0) { fNextToken = loc + 1; if (!fNextToken || !*fNextToken) AdvanceToNextToken(); return; } } else if (*loc == '{' || *loc == '"') { // quoted or literal fNextToken = loc; char *a = CreateString(); PR_FREEIF(a); break; // move to next token } } if (ContinueParse()) AdvanceToNextToken(); } }
WOGText* OGTextConfig::Parser(const QString & language) { WOGText* obj; QDomNode node; QDomElement element; obj = new WOGText; obj->language = language; node = rootElement.firstChild(); while(!node.isNull()) { element = node.toElement(); if (element.tagName() == "string") { obj->string << CreateString(element, language); } node = node.nextSibling(); } return obj; }
int MyMeshText::CreateStringColorShadowZAndRot(bool concat, float fontheight, float x, float y, float z, float rotz, unsigned char justificationflags, ColorByte color, ColorByte shadowcolor, float shadowoffx, float shadowoffy, Vector2 size, const char* text, ...) { const char* stringtodraw = text; if( g_pLanguageTable != 0 && text[0] == '.' ) stringtodraw = g_pLanguageTable->LookUp( text ); char* tempbuffer = g_pRTQGlobals->m_TempBuffer; va_list arg; va_start( arg, text ); vsnprintf_s( tempbuffer, sizeof(g_pRTQGlobals->m_TempBuffer), _TRUNCATE, stringtodraw, arg ); va_end(arg); CreateString( concat, fontheight, x+shadowoffx, y+shadowoffy, z, rotz, justificationflags, shadowcolor, size, tempbuffer ); concat = true; return CreateString( concat, fontheight, x, y, z, rotz, justificationflags, color, size, tempbuffer ); }
void FloorManager::InvokeUserInteraction() { //initialise variables int commandId, floorNumber,roomCount; string name, message; //get floor information and assign to variables roomCount = floorModel->rooms.size(); floorNumber = floorModel->GetFloorNumber(); name = floorModel->GetName(); message = CreateString(); //top level interaction is repeating loop while(true) { //show the floor info as a welcome message; floorUI->ShowFloorInfo(name,floorNumber); //show the menu and get user command commandId = floorUI->GetUserCommand(message); //user wants to exit this interaction if((commandId < 0) || (commandId >= roomCount)) break; //Create RoomManager and invoke InvokeUserInteraction method RoomManager* roomManager = new RoomManager(floorModel->rooms.at(commandId)); roomManager->InvokeUserInteraction(); delete roomManager; } }
ALERROR CCodeChain::DefineGlobal (const CString &sVar, ICCItem *pValue) // DefineGlobal // // Defines a global variable programmatically { ALERROR error; // Create a string item ICCItem *pVar = CreateString(sVar); // Add the symbol ICCItem *pError; pError = m_pGlobalSymbols->AddEntry(this, pVar, pValue); pVar->Discard(this); // Check for error if (pError->IsError()) error = ERR_FAIL; else error = NOERROR; pError->Discard(this); return error; }
ICCItem *CCodeChain::CreateError (const CString &sError, ICCItem *pData) // CreateError // // Creates an item // // sError: Error messages // pData: Item that caused error. { ICCItem *pError; CString sArg; CString sErrorLine; // Convert the argument to a string if (pData) { sArg = pData->Print(this); sErrorLine = strPatternSubst(LITERAL("%s [%s]"), sError, sArg); } else sErrorLine = sError; // Create the error pError = CreateString(sErrorLine); pError->SetError(); return pError; }
ALERROR CCodeChain::DefineGlobalString (const CString &sVar, const CString &sValue) { ALERROR error; ICCItem *pValue = CreateString(sValue); error = DefineGlobal(sVar, pValue); pValue->Discard(this); return error; }
void StatusManager::InvokeUserInteraction() { //create string to be displayed in the UI string message = CreateString(); //display the device status and waits for user input to continue statusUI->GetUserCommand(message); }
void Login::GetFollowingList() { FILE* file = fopen("settings.txt","w"); assert(file != NULL); NaString userName = {0}; CreateString("User="******"\n",&userName); fwrite(userName.text,strlen(userName.text),1,file); fclose(file); NaString passUserName = { 0 }; CreateString(edit->toPlainText().toAscii().data(),&passUserName); assert(followsUpdater!=NULL); if (followsUpdater->follows != NULL) { delete followsUpdater->follows; followsUpdater->follows = NULL; } assert(table !=NULL); table->clear(); table->setRowCount(0); table->setHorizontalHeaderLabels(QString("Followers;Status").split(";")); testing = new GetUserFollowers(); assert(testing != NULL); testing->init(&passUserName); followsUpdater->table = table; followsUpdater->follows = testing; followsUpdater->run(); this->hide(); }
void InitInterface_RR(string iniName,ref myCh,ref enemyCh) { refMyCharacter = myCh; refEnemyCharacter = enemyCh; GameInterface.title = "titleRansack"; SendMessage(&GameInterface,"ls",MSG_INTERFACE_INIT,iniName); SetVariable(); ref shipRef = GetShipByType(sti(refMyCharacter.ship.Type)); CreateImage("myShip","SHIPS",shipRef.name,32,39,160,167); CreateImage("myFace","FACE128_"+refMyCharacter.FaceId,"face",164,39,292,167); CreateString(TRUE,"MyShipType",XI_ConvertString(shipRef.Name),FONT_NORMAL,COLOR_NORMAL,96,140,SCRIPT_ALIGN_CENTER,1.0); CreateString(TRUE,"MyShipName",refMyCharacter.ship.Name,FONT_NORMAL,COLOR_NORMAL,177,198,SCRIPT_ALIGN_CENTER,1.0); shipRef = GetShipByType(sti(refEnemyCharacter.ship.Type)); CreateImage("enemyShip","SHIPS",shipRef.name,480,39,608,167); CreateImage("enemyFace","FACE128_"+refEnemyCharacter.FaceId,"face",348,39,476,167); CreateString(TRUE,"EnemyShipType",XI_ConvertString(shipRef.Name),FONT_NORMAL,COLOR_NORMAL,544,140,SCRIPT_ALIGN_CENTER,1.0); CreateString(TRUE,"EnemyShipName",refEnemyCharacter.ship.Name,FONT_NORMAL,COLOR_NORMAL,463,198,SCRIPT_ALIGN_CENTER,1.0); CreateString(TRUE,"String1",XI_ConvertString(str1),FONT_NORMAL,COLOR_NORMAL,320,240,SCRIPT_ALIGN_CENTER,1.0); CreateString(TRUE,"String2",XI_ConvertString(str2),FONT_NORMAL,COLOR_NORMAL,320,268,SCRIPT_ALIGN_CENTER,1.0); CreateString(TRUE,"String3",XI_ConvertString(str3_1)+" "+nSurrenderedMen+" "+XI_ConvertString(str3_2),FONT_NORMAL,COLOR_NORMAL,320,296,SCRIPT_ALIGN_CENTER,1.0); SetEventHandler("InterfaceBreak","ProcessCancelExit",0); SetEventHandler("InterfaceCancel","ProcessCancelExit",0); SetEventHandler("KillPress","KillProcess",0); SetEventHandler("SlavesPress","SlavesProcess",0); }
string CopyString(string s) { string newstr; if (s == NULL) Error("NULL string passed to CopyString"); newstr = CreateString(strlen(s)); strcpy(newstr, s); return (newstr); }
string CharToString(char ch) { string result; result = CreateString(1); result[0] = ch; result[1] = '\0'; return (result); }
TITANIUM_PROPERTY_GETTER(Binding, ConverterLanguage) { auto value = unwrap()->ConverterLanguage; auto context = get_context(); auto result = context.CreateString(TitaniumWindows::Utility::ConvertUTF8String(value)); return result; }
TITANIUM_FUNCTION(File, getDirectoryListing) { auto listing = getDirectoryListing(); auto context = get_context(); std::vector<JSValue> result; for (size_t i = 0; i < listing.size(); i++) { result.push_back(context.CreateString(listing.at(i))); } return context.CreateArray(result); }
void DefglobalSetString( Defglobal *theDefglobal, const char *value) { CLIPSValue cv; cv.lexemeValue = CreateString(theDefglobal->header.env,value); DefglobalSetValue(theDefglobal,&cv); }
// // Constructor // PathSearch::PathSearch(const char *name) : Base(name), start(-1, -1), end(-1, -1), rescan(FALSE) { // Create interface vars varType = CreateString("type", ""); varOptimize = CreateInteger("optimize", FALSE, 0, 1); }
void testStringIndex() { printf("input the main string:\n"); SString S; CreateString(S); PrintString(S); printf("input the sub string:\n"); SString S2; CreateString(S2); PrintString(S2); printf("general matching algirothm:\n"); int pos = Index(S, S2, 1); printf("the position of the substring in the main string is: %d\n", pos); printf("kmp matching algirothm:\n"); pos = Index_KMP(S, S2, 1); printf("the position of the substring in the main string is: %d\n", pos); }
TITANIUM_PROPERTY_GETTER(Button, image) { const auto ctx = get_context(); if (imageAsBlob__ != nullptr) { return imageAsBlob__->get_object(); } else if (!image__.empty()) { return ctx.CreateString(get_image()); } else { return ctx.CreateNull(); } }
JSON *Duplicate(JSON *obj, int recurse){ switch (obj->type){ case JSON_NULL: return CreateNULL(); case JSON_TRUE: return CreateTrue(); case JSON_FALSE: return CreateFalse(); case JSON_NUMBER: return CreateNumber(obj->valuedouble); case JSON_STRING: return CreateString(obj->valuestring); case JSON_ARRAY:{ JSON *new_obj = CreateArray(); if (recurse == 0) new_obj->son = obj->son; else{ if (obj->son != NULL){ new_obj->son = Duplicate(obj->son, 1); JSON *old_item = obj->son, *new_item = new_obj->son; for ( ; old_item->next != NULL; old_item = old_item->next, new_item = new_item->next){ JSON *temp = Duplicate(old_item->next,1); new_item->next = temp; temp->last = new_item; } } } return new_obj; } case JSON_OBJECT:{ JSON *new_obj = CreateObject(); if (recurse == 0) new_obj->son = obj->son; else{ if (obj->son != NULL){ new_obj->son = Duplicate(obj->son, 1); JSON *old_item = obj->son, *new_item = new_obj->son; for ( ; old_item->next != NULL; old_item = old_item->next, new_item = new_item->next){ JSON *temp = Duplicate(old_item->next,1); new_item->next = temp; temp->last = new_item; } } } return new_obj; } case JSON_ENTRY:{ JSON *new_obj = CreateEntry(obj->key, Duplicate(obj->value,1)); return new_obj; } default: return NULL; } }
ns3__GetEndpointsRequest* Soap::Serialize(soap* s, const GetEndpointsRequest& opcua) { ns3__GetEndpointsRequest* request = soap_new_ns3__GetEndpointsRequest(s, 1); request->RequestHeader = CreateRequestHeader(s, opcua.Header); if (!opcua.Filter.EndpointURL.empty()) request->EndpointUrl = CreateString(s, opcua.Filter.EndpointURL); if (!opcua.Filter.LocaleIDs.empty()) request->LocaleIds = CreateListOfStrings(s, opcua.Filter.LocaleIDs); if (!opcua.Filter.ProfileUries.empty()) request->ProfileUris = CreateListOfStrings(s, opcua.Filter.ProfileUries); return request; }