void MD_Runner::run() { fprintf(stderr, "V8 version %s [mordor shell]\n", v8::V8::GetVersion()); v8::Platform* v8_platform = v8::platform::CreateDefaultPlatform(1); v8::V8::InitializeICU(); v8::V8::InitializePlatform(v8_platform); v8::V8::Initialize(); int argc = g_argc; v8::V8::SetFlagsFromCommandLine(&argc, g_argv, true); v8::V8::SetFlagsFromString(MD_V8_OPTIONS, sizeof(MD_V8_OPTIONS) - 1); v8::V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton); v8::Isolate* isolate = v8::Isolate::New(); { v8::Isolate::Scope isolate_scope(isolate); v8::Locker locker(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> context = v8::Context::New(isolate); v8::Context::Scope context_scope(context); Environment* env = Environment::New(context, Scheduler::getThis()); ProcessObject po(env); po.setup(); { Coroutine<const char*> coReadScript(&readScript); const char* script; bool running = true; do { script = coReadScript.call(); if (coReadScript.state() == Fiber::State::TERM) { break; } v8::HandleScope handle_scope(context->GetIsolate()); v8::Local<v8::String> script_str = Utf8String(isolate, script); ExecuteString(env, script_str, Utf8String(isolate, "md_shell")); running = env->running(); } while (running); std::cout << "bye." << std::endl; } Environment::environment.reset(); } isolate->Dispose(); LineEditor* line_editor = LineEditor::Get(); if (line_editor) line_editor->Close(); v8::V8::Dispose(); v8::V8::ShutdownPlatform(); delete v8_platform; this->over(); }
FileContainer TranslationUnit::fileContainer() const { checkIfNull(); return FileContainer(d->filePath, d->projectPart.projectPartId(), Utf8String(), false, d->documentRevision); }
Utf8String UnsavedFile::lineRange(uint fromLine, uint toLine) const { if (fromLine > toLine) return Utf8String(); // Find start of first line bool ok = false; const uint fromPosition = toUtf8Position(fromLine, 1, &ok); QTC_ASSERT(ok, return Utf8String()); // Find end of last line uint toPosition = toUtf8Position(toLine, 1, &ok); QTC_ASSERT(ok, return Utf8String()); const uint endPosition = uint(m_fileContent.byteSize()); while (toPosition < endPosition && m_fileContent.constData()[toPosition] != '\n') ++toPosition; return m_fileContent.mid(int(fromPosition), int(toPosition - fromPosition)); }
Utf8StringVector SqliteStatement::columnNames() const { Utf8StringVector columnNames; int columnCount = SqliteStatement::columnCount(); columnNames.reserve(columnCount); for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) columnNames.append(Utf8String(sqlite3_column_origin_name(compiledStatement.get(), columnIndex), -1)); return columnNames; }
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments(CppTools::ProjectPart *projectPart) const { const auto projectPartId = projectPart ? Utf8String::fromString(projectPart->id()) : Utf8String(); const QStringList theFileArguments = fileArguments(filePath(), projectPart); return {filePath(), projectPartId, Utf8StringVector(theFileArguments), revision()}; }
FileContainer Document::fileContainer() const { checkIfNull(); return FileContainer(d->filePath, d->projectPart.id(), d->fileArguments, Utf8String(), false, d->documentRevision); }
void Path::AppendExtension( const std::string& extension ) { if ( extension.empty() ) { return; } const std::string path = this->ToString(); const std::string result = ( '.' == extension[0] ) ? path + extension : path + '.' + extension; m_impl.reset( new PathImpl( Utf8String( result ))); }
Class* initialize(ClassMap * classMap) { if (staticClassPtr != NULL) { return staticClassPtr; } Class * newClass = new Class(NULL); staticClassPtr = newClass; newClass->classLoader = NULL; newClass->parentClass = classMap->getClass("java/lang/Object"); newClass->fullyQualifiedName = Utf8String("java/lang/Array"); return newClass; }
Class* initialize(ClassMap * classMap) { Class * newClass = new Class(NULL); staticClassPtr = newClass; newClass->classLoader = NULL; newClass->parentClass = classMap->getClass("java/lang/Object"); newClass->fullyQualifiedName = Utf8String("java/lang/String"); newClass->addMethod(getNativeMethod("<init>", "()V", &init)); newClass->addMethod(getNativeMethod("toString", "()Ljava/lang/String;", &toString)); newClass->addMethod(getNativeMethod("clone", "()Ljava/lang/Object;", &clone)); newClass->addMethod(getNativeMethod("hashCode", "()I", &hashCode)); newClass->addMethod(getNativeMethod("length", "()I", &length)); return newClass; }
void ProgramOptionsManager::ParseCommandLine() { namespace po = boost::program_options; std::vector< std::string > arguments; // NOTES: split_winmain() suppose the parameter is the lpCmdLine in WinMain(), // but the return value of GetCommandLine() has prepended the program path. // We need to remove the first argument manually, therefore the for loop // starts at 1, not 0. const std::vector< std::wstring > wargs = po::split_winmain( ::GetCommandLineW() ); // Omit the first argument. for ( Uint i = 1; i < wargs.size(); ++ i ) { arguments.push_back( Utf8String( wargs[i] ).ToString() ); } this->ParseArguments( arguments ); }
int BaseFontBitmap::getTextWidth(const byte *text, int maxLength) { AnsiString str; if (_gameRef->_textEncoding == TEXT_UTF8) { WideString wstr = StringUtil::utf8ToWide(Utf8String((const char *)text)); str = StringUtil::wideToAnsi(wstr); } else { str = AnsiString((const char *)text); } if (maxLength >= 0 && str.size() > (uint32)maxLength) { str = Common::String(str.c_str(), (uint32)maxLength); } //str.substr(0, maxLength); // TODO: Remove int textWidth = 0; for (int i = 0; (uint32)i < str.size(); i++) { textWidth += getCharWidth((byte)str[i]); } return textWidth; }
Utf8String Utf8String::fromByteArray(const QByteArray &utf8ByteArray) { return Utf8String(utf8ByteArray); }
int BaseFontBitmap::textHeightDraw(const byte *text, int x, int y, int width, TTextAlign align, bool draw, int maxHeight, int maxLength) { if (maxLength == 0) { return 0; } if (text == nullptr || text[0] == '\0') { return _tileHeight; } AnsiString str; if (_gameRef->_textEncoding == TEXT_UTF8) { WideString wstr = StringUtil::utf8ToWide(Utf8String((const char *)text)); str = StringUtil::wideToAnsi(wstr); } else { str = AnsiString((const char *)text); } if (str.empty()) { return 0; } int lineLength = 0; int realLength = 0; int numLines = 0; int i; int index = -1; int start = 0; int end = 0; int last_end = 0; bool done = false; bool newLine = false; bool longLine = false; if (draw) { _gameRef->_renderer->startSpriteBatch(); } while (!done) { if (maxHeight > 0 && (numLines + 1)*_tileHeight > maxHeight) { if (draw) { _gameRef->_renderer->endSpriteBatch(); } return numLines * _tileHeight; } index++; if (str[index] == ' ' && (maxHeight < 0 || maxHeight / _tileHeight > 1)) { end = index - 1; realLength = lineLength; } if (str[index] == '\n') { end = index - 1; realLength = lineLength; newLine = true; } if (lineLength + getCharWidth(str[index]) > width && last_end == end) { end = index - 1; realLength = lineLength; newLine = true; longLine = true; } if ((int)str.size() == (index + 1) || (maxLength >= 0 && index == maxLength - 1)) { done = true; if (!newLine) { end = index; lineLength += getCharWidth(str[index]); realLength = lineLength; } } else { lineLength += getCharWidth(str[index]); } if ((lineLength > width) || done || newLine) { if (end < 0) { done = true; } int startX; switch (align) { case TAL_CENTER: startX = x + (width - realLength) / 2; break; case TAL_RIGHT: startX = x + width - realLength; break; case TAL_LEFT: startX = x; break; default: error("BaseFontBitmap::TextHeightDraw - Unhandled enum"); break; } for (i = start; i < end + 1; i++) { if (draw) { drawChar(str[i], startX, y); } startX += getCharWidth(str[i]); } y += _tileHeight; last_end = end; if (longLine) { end--; } start = end + 2; index = end + 1; lineLength = 0; newLine = false; longLine = false; numLines++; } } if (draw) { _gameRef->_renderer->endSpriteBatch(); } return numLines * _tileHeight; }
ClangString::operator Utf8String() const { return Utf8String(clang_getCString(cxString), -1); }
Utf8String PathImpl::ToUtf8String() const { return Utf8String( this->native() ); }
Utf8String Utf8String::mid(int position, int length) const { return Utf8String(byteArray.mid(position, length)); }
Utf8String Utf8String::fromUtf8(const char *utf8Text) { return Utf8String(utf8Text, -1); }
const Utf8String operator+(const Utf8String &first, const Utf8String &second) { return Utf8String(first.byteArray + second.byteArray); }
ClangString::operator Utf8String() const { return Utf8String(cString(), -1); }