static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); if (!view) return JSValueMakeUndefined(context); if (argumentCount < 3) return JSValueMakeUndefined(context); JSStringRef string = JSValueToStringCopy(context, arguments[0], exception); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string); GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize))); JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize); JSStringRelease(string); int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception)); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); int end = static_cast<int>(JSValueToNumber(context, arguments[2], exception)); g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, end); return JSValueMakeUndefined(context); }
bool ZLXMLReader::readDocument(shared_ptr<ZLInputStream> stream) { if (!stream || !stream->open()) { return false; } bool useWindows1252 = false; if (ZLEncodingCollection::useWindows1252Hack()) { stream->read(myParserBuffer, 256); std::string stringBuffer(myParserBuffer, 256); stream->seek(0, true); int index = stringBuffer.find('>'); if (index > 0) { stringBuffer = ZLUnicodeUtil::toLower(stringBuffer.substr(0, index)); int index = stringBuffer.find("\"iso-8859-1\""); if (index > 0) { useWindows1252 = true; } } } initialize(useWindows1252 ? "windows-1252" : 0); size_t length; do { length = stream->read(myParserBuffer, BUFFER_SIZE); if (!readFromBuffer(myParserBuffer, length)) { break; } } while ((length == BUFFER_SIZE) && !myInterrupted); stream->close(); shutdown(); return true; }
String String::fromUTF8(const char* stringStart, size_t length) { if (!stringStart) return String(); // We'll use a StringImpl as a buffer; if the source string only contains ascii this should be // the right length, if there are any multi-byte sequences this buffer will be too large. UChar* buffer; String stringBuffer(StringImpl::createUninitialized(length, buffer)); UChar* bufferEnd = buffer + length; // Try converting into the buffer. const char* stringCurrent = stringStart; if (convertUTF8ToUTF16(&stringCurrent, stringStart + length, &buffer, bufferEnd) != conversionOK) return String(); // stringBuffer is full (the input must have been all ascii) so just return it! if (buffer == bufferEnd) return stringBuffer; // stringBuffer served its purpose as a buffer, copy the contents out into a new string. unsigned utf16Length = buffer - stringBuffer.characters(); ASSERT(utf16Length < length); return String(stringBuffer.characters(), utf16Length); }
QString ParameterType::ToString() const { if (str.isEmpty()) { QTextStream stringBuffer(&str); stringBuffer << "ParameterType(" << id << "," << defined << ")"; } return str; }
string ReadFile(const string& filename){ ifstream fileIn(filename); if (!fileIn.good()){ cerr << "Could not load shader: " << filename << endl; return ""; } string stringBuffer(istreambuf_iterator<char>(fileIn), (istreambuf_iterator<char>())); return stringBuffer; }
std::string getErrorMsg(int err) { std::string s; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err ? err:GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language stringBuffer(s, 1024), 1024, NULL ); return s; }
std::string S3::getDate() { time_t lt; time(<); struct tm * tmTmp; tmTmp = gmtime(<); char buf[37]; strftime(buf,37,"%a, %d %b %Y %X GMT",tmTmp); std::string stringBuffer(buf); return stringBuffer; }
string GLSLProgram::ReadFile( const string& filename ) { ifstream fileIn(filename.c_str()); if (!fileIn.good()) { PRINT_WARN("Shader %s Error", filename.c_str()); return string(); } string stringBuffer(std::istreambuf_iterator<char>(fileIn), (std::istreambuf_iterator<char>())); return stringBuffer; }
bool Terrain::loadHeightmap(const string& rawFile, int width) { const float HEIGHT_SCALE = 10.0f; std::ifstream fileIn(rawFile.c_str(), std::ios::binary); if (!fileIn.good()) { std::cout << "File does not exist" << std::endl; return false; } string stringBuffer(std::istreambuf_iterator<char>(fileIn), (std::istreambuf_iterator<char>())); fileIn.close(); if (stringBuffer.size() != (width * width)) { std::cout << "Image size does not match passed width" << std::endl; return false; } vector<float> heights; heights.reserve(width * width); for (int i = 0; i < (width * width); ++i) { float value = (float)(unsigned char)stringBuffer[i] / 256.0f; heights.push_back(value * HEIGHT_SCALE); m_colors.push_back(Color(value, value, value)); } glGenBuffers(1, &m_colorBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * m_colors.size() * 3, &m_colors[0], GL_STATIC_DRAW); generateVertices(heights, width); generateIndices(width); generateTexCoords(width); generateNormals(); generateWaterVertices(width); generateWaterIndices(width); generateWaterTexCoords(width); m_width = width; return true; }
boolType LuaScript::loadScript(stringType filePath) { std::ifstream scriptFile (filePath); if (scriptFile.is_open()) { stringType stringBuffer((std::istreambuf_iterator<char>(scriptFile)), std::istreambuf_iterator<char>()); scriptFile.close(); return this->loadString(stringBuffer, filePath); } else { std::cerr << "LUA_ERROR: Failed to load script --> " << filePath << std::endl; return false; } }
bool EngineUtils::readFileToSTDString(const char* fileLoc, std::string& dstString) { std::ifstream file(fileLoc); if (file.fail()) { fprintf(stderr, "Error reading file %s", fileLoc); return false; } std::string stringBuffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); dstString.assign(stringBuffer); return true; }
bool File::WriteDouble(double aDouble) { if(myFlags.test(BINARY)) { fwrite(&aDouble,sizeof(double),1,myFile); } else { char buffer[256]; sprintf(buffer,"%g", aDouble); std::string stringBuffer(buffer); fwrite(stringBuffer.c_str(),sizeof(char),stringBuffer.size(),myFile); char tempchar = ' '; fwrite(&tempchar,sizeof(char),1,myFile); } return true; }
bool File::WriteFloat(float aFloat) { if(myFlags.test(BINARY)) { fwrite(&aFloat,sizeof(float),1,myFile); } else { char buffer[256]; sprintf(buffer,"%f", aFloat); std::string stringBuffer(buffer); fwrite(stringBuffer.c_str(),sizeof(char),stringBuffer.size(),myFile); char tempchar = ' '; fwrite(&tempchar,sizeof(char),1,myFile); } return true; }
bool File::WriteInt(int aInteger) { if(myFlags.test(BINARY)) { fwrite(&aInteger,sizeof(int),1,myFile); } else { char buffer[256]; sprintf(buffer,"%i", aInteger); std::string stringBuffer(buffer); fwrite(stringBuffer.c_str(),sizeof(char),stringBuffer.size(),myFile); char tempchar = ' '; fwrite(&tempchar,sizeof(char),1,myFile); } return true; }
static int writeToStringBuilder(void* context, const char* buffer, int len) { StringBuilder& resultOutput = *static_cast<StringBuilder*>(context); if (!len) return 0; StringBuffer<UChar> stringBuffer(len); UChar* bufferUChar = stringBuffer.characters(); UChar* bufferUCharEnd = bufferUChar + len; const char* stringCurrent = buffer; WTF::Unicode::ConversionResult result = WTF::Unicode::convertUTF8ToUTF16(&stringCurrent, buffer + len, &bufferUChar, bufferUCharEnd); if (result != WTF::Unicode::conversionOK && result != WTF::Unicode::sourceExhausted) { ASSERT_NOT_REACHED(); return -1; } int utf16Length = bufferUChar - stringBuffer.characters(); resultOutput.append(stringBuffer.characters(), utf16Length); return stringCurrent - buffer; }
String OVRError::GetErrorString() const { StringBuffer stringBuffer("OVR Error:\n"); // Code OVR::String errorCodeString; GetErrorCodeString(Code, false, errorCodeString); stringBuffer.AppendFormat(" Code: %d -- %s\n", Code, errorCodeString.ToCStr()); // SysCode if (SysCode != ovrSysErrorCodeSuccess) { OVR::String sysErrorString; GetSysErrorCodeString(SysCode, false, sysErrorString); OVRRemoveTrailingNewlines(sysErrorString); stringBuffer.AppendFormat(" System error: %d (%x) -- %s\n", (int)SysCode, (int)SysCode, sysErrorString.ToCStr()); } // Description if (Description.GetLength()) { stringBuffer.AppendFormat(" Description: %s\n", Description.ToCStr()); } // OVRTime stringBuffer.AppendFormat(" OVRTime: %f\n", OVRTime); // SysClockTime OVR::String sysClockTimeString; OVRFormatDateTime(ClockTime, sysClockTimeString); stringBuffer.AppendFormat(" Time: %s\n", sysClockTimeString.ToCStr()); // Context if (Context.GetLength()) { stringBuffer.AppendFormat(" Context: %s\n", Context.ToCStr()); } // If LogLine is set, if (LogLine != kLogLineUnset) { stringBuffer.AppendFormat(" LogLine: %lld\n", LogLine); } // FILE/LINE if (SourceFilePath.GetLength()) { stringBuffer.AppendFormat(" File/Line: %s:%d\n", SourceFilePath.ToCStr(), SourceFileLine); } // Backtrace if (Backtrace.GetSize()) { // We can trace symbols in a debug build here or we can trace just addresses. See other code for // examples of how to trace symbols. stringBuffer.AppendFormat(" Backtrace: "); for (size_t i = 0, iEnd = Backtrace.GetSize(); i != iEnd; ++i) stringBuffer.AppendFormat(" %p", Backtrace[i]); stringBuffer.AppendChar('\n'); } return OVR::String(stringBuffer.ToCStr(), stringBuffer.GetSize()); }