BString ParseArgvZeroFromString(const char* command) { char* ret = NULL; // make our own copy of the string... int slen = strlen(command); // need an extra nul byte to get GetNextWord() to stop char* cmd = new char[slen + 2]; strcpy(cmd, command); cmd[slen + 1] = '\0'; // zero out the second nul byte GunkSpaces(cmd); RemoveQuotes(cmd); char* beginWord = NULL, *endWord = cmd - 1; if (GetNextWord(&beginWord, &endWord)) { ret = new char[strlen(beginWord) + 1]; strcpy(ret, beginWord); UnGunk(ret); } delete [] cmd; BString retStr(ret?ret:""); delete [] ret; return retStr; }
std::string base_string::string_To_UTF8(const std::string & str) { int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pwBuf = new wchar_t[nwLen + 1]; memset(pwBuf, 0, (nwLen + 1)*sizeof(wchar_t)); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + 1]; memset(pBuf, 0, nLen + 1); ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete []pwBuf; delete []pBuf; pwBuf = NULL; pBuf = NULL; return retStr; }
Buffer Iconv::encode(const string& str, const string& encoding, bool /*stripBOM*/ /*= false*/) { if (encoding == "utf-8" || encoding == "utf8") { int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴 ZeroMemory(pwBuf, nwLen * 2 + 2); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + 1]; ZeroMemory(pBuf, nLen + 1); ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete[]pwBuf; delete[]pBuf; pwBuf = NULL; pBuf = NULL; return Buffer(retStr); } Buffer buf((size_t)0); return buf; }
//------------------------------------------------------------------------------------ void readRecentFiles(QSettings& settings) { int recentFileCount = settings.value("recentfiles/count").toInt(); Ogitors::UTFStringVector recentList; recentList.clear(); for(int i = 0;i < recentFileCount;i++) { QTextCodec *codec = QTextCodec::codecForName("UTF-16"); QString value = settings.value(QString("recentfiles/entry%1").arg(i)).toString(); if(!QFile::exists(value)) continue; QByteArray encodedString = codec->fromUnicode(value); Ogre::ushort *data = (Ogre::ushort*)encodedString.data(); data++; Ogre::UTFString retStr(data,(encodedString.size() / 2) - 1); recentList.push_back(retStr); } Ogitors::OgitorsRoot::getSingletonPtr()->InitRecentFiles(recentList); }
/** * 復号化 * * @param inStr 入力文字列 * * @return 復号化文字列 */ string EncryptUtil::decrypt(const string &inStr) { // Base64デコード vector<unsigned char> buff; auto isSuccess = Base64Util::decode(inStr, buff); if (!isSuccess) { return ""; } // 復号化 int decryptLen = 0; int paddingLen = 0; vector<unsigned char> decrypt(buff.size()); // TODO: 後で考える // EVP_CIPHER_CTX context; // EVP_DecryptInit(&context, EVP_aes_128_ecb(), (unsigned char*)EncryptConst::saveDataEncryptKey.c_str(), nullptr); // EVP_DecryptUpdate(&context, decrypt.data(), &decryptLen, buff.data(), (int)buff.size()); // EVP_DecryptFinal(&context, decrypt.data() + decryptLen, &paddingLen); // EVP_CIPHER_CTX_cleanup(&context); // 復号化したデータを文字列に変換 string retStr((char *)decrypt.data(), decryptLen + paddingLen); // メモリ解放 EVP_cleanup(); return retStr; }
std::string RtMidiOutJack :: getPortName( unsigned int portNumber ) { JackMidiData *data = static_cast<JackMidiData *> (apiData_); std::ostringstream ost; std::string retStr(""); // List of available ports const char **ports = jack_get_ports( data->client, NULL, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput ); // Check port validity if ( ports == NULL) { errorString_ = "RtMidiOut::getPortName: no ports available!"; error( RtError::WARNING ); return retStr; } if ( ports[portNumber] == NULL) { ost << "RtMidiOut::getPortName: the 'portNumber' argument (" << portNumber << ") is invalid."; errorString_ = ost.str(); error( RtError::WARNING ); } else retStr.assign( ports[portNumber] ); free( ports ); return retStr; }
std::string MySQL::Escape(const std::string &str) { char *tmp = new char[str.length() * 2 + 1]; this->mtx.lock(); mysql_real_escape_string(this->con, tmp, str.c_str(), str.length()); this->mtx.unlock(); std::string retStr(tmp); delete [] tmp; return retStr; }
string JavaJSImpl::scopeGetString( jlong id , const char * field ) { jstring s1 = _getEnv()->NewStringUTF( field ); jstring s = (jstring)_getEnv()->CallStaticObjectMethod( _dbhook , _scopeGetString , id , s1 ); _getEnv()->DeleteLocalRef( s1 ); if ( ! s ) return ""; const char * c = _getEnv()->GetStringUTFChars( s , 0 ); string retStr(c); _getEnv()->ReleaseStringUTFChars( s , c ); return retStr; }
TEST(IniFile, escapedChars) { IniFile ini("/tmp/testini.conf"); // Verify special characters in set EXPECT_TRUE(ini.setSection("Section", true)); EXPECT_TRUE(ini.set("key", "line\\1\nline\\2\nline\\3")); EXPECT_EQ("[Section]\nkey=line\\\\1\\nline\\\\2\\nline\\\\3\n", ini.getRawConfiguration()); // Verify special characters in get string retStr(""); EXPECT_TRUE(ini.get("key", retStr)); EXPECT_EQ("line\\1\nline\\2\nline\\3", retStr); }
string TimeTransform::dateInFormat(time_t dateTime ,string stringFormat) { char buffer[80]; const char *format = stringFormat.c_str(); struct tm * timeinfo; timeinfo = localtime(&dateTime); strftime(buffer, 80, format, timeinfo); string retStr(buffer); return retStr; }
std::string ShaderProgram::getLinkerLog() const { GLint len; glGetProgramiv(id, GL_INFO_LOG_LENGTH , &len); if (len > 1) { GLchar* log = new GLchar[len]; if (log == 0) return "Memory allocation for log failed!"; GLsizei l; // length returned glGetProgramInfoLog(id, len, &l, log); std::string retStr(log); delete[] log; return retStr; } return ""; }
std::string _intToB64ID(IntType intVal) { const int size = sizeof(IntType) / 4 * 3; // ignore the first 1/4 bytes const int sizeEnc = sizeof(IntType); // base64 adds 1/3 of size again base64::encoder enc; base64_init_encodestate(&enc._state); char* cstr = new char[sizeEnc + 1]; enc.encode(reinterpret_cast<char*>(&intVal), size, cstr); cstr[sizeEnc] = '\0'; std::string retStr(cstr); // it's no problem to use a '/' in the URL, but '_' looks better for(size_t pos = retStr.find('/'); pos != std::string::npos; pos = retStr.find('/', pos + 1)) retStr.at(pos) = '_'; return retStr; }
string convert(string s, int numRows) { if (1 == numRows || s.size() == 1) return s; int index=0; int N;//the group counts ,each group has (numRows+1) members. int strLen = s.size(); string retStr(strLen + 1, '\0'); int mid;//middle rows if (numRows%2)//odd rows mid = numRows / 2; else mid = numRows / 2 -1; N = strLen / (numRows+1);// N may be zero when the size of the string <= numRows if (!N) return s; if (strLen % N) N += 1; for (int j = 0; j < numRows; ++j)//j is the offset in the group { for (int i = 0; i < N; ++i)//i is the offset of the group { int m = i * (numRows+1) + j; if (m < strLen) { retStr[index++] = s[m]; if (j == mid) { int mm = i * (numRows + 1) + numRows; if (mm < strLen) retStr[index++] = s[mm]; } } } } return retStr; }
std::string CBWHelper::StringFormat(const char * fmt, ...) { int result = -1, length = 256; char *buffer = NULL; va_list args; va_start(args, fmt); while (result == -1) { if (buffer) delete[] buffer; buffer = new char[length + 1]; memset(buffer, 0x00, length + 1); result = _vsnprintf_s(buffer,length, _TRUNCATE, fmt, args); length *= 2; } va_end(args); std::string retStr(buffer); delete[] buffer; return retStr; }
std::string string_To_UTF8(const std::string & str) { int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pwBuf = new wchar_t[nwLen + 1];//一定要加1,不然会出现尾巴 ZeroMemory(pwBuf, nwLen * 2 + 2); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen); int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL); char * pBuf = new char[nLen + 1]; ZeroMemory(pBuf, nLen + 1); ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL); std::string retStr(pBuf); delete []pwBuf; delete []pBuf; pwBuf = NULL; pBuf = NULL; return retStr; }
std::string Utils::trimCopy(const std::string& str) { std::string retStr(str); trim(retStr); return retStr; }
std::string Utils::toLowerCopy(const std::string& str) { std::string retStr(str); toLower(retStr); return retStr; }
int lh_argv(lua_State *L) { checkArg(L, 1, "argv"); int i = luaInt(1); if(i < 0 || i >= gargc) return 0; return retStr(L, gargv[i]); }
int lh_noteyestats(lua_State *L) { return retStr(L, noteyeStats()); }
int lh_geterrormsg(lua_State *L) { return retStr(L, noteyeerrbuf); return 0; }