void CustomDrawMeshRenderBatch::Print(HeapString& ioStr, uint level) { ioStr.AppendFormat("{:x}", this); ioStr.Append('\t', level); ioStr.AppendFormat("{}:{}\t", mNode->Id(), mNode->Name()); ioStr.AppendLine(); }
bool FileStorage::SearchDirectoriesToAdd(const StringRef& searchPath, DirectoryEntry* destDir /*= nullptr*/, bool recursively /*= true*/) { if (destDir == nullptr) { destDir = &mRootDir; } List<HeapString> dirList; Directory::SearchDirectories(searchPath, dirList, recursively); HeapString searchDir = Path::GetDirectory(searchPath); for (auto& dir : dirList) { StringRef subDir; if (searchDir.IsEmpty()) { subDir = dir; } else { subDir = dir.ToString().SubString(searchDir.Length() + 1); //+1 to skip '/' } auto* dirEntry = FindOrCreateDirectoryEntry(subDir, destDir); if (dirEntry == nullptr) { Log::FormatError("Cannot create dir:{}", subDir); return false; } Log::FormatInfo("Add Dir:{}", dir); } return true; }
TextureAtlasRegion* MedusaTextureAtlas::CreateAtlasRegion(const IStream& stream) { HeapString outLine; List<HeapString> outValues; std::unique_ptr<TextureAtlasRegion> region(new TextureAtlasRegion()); //read source texture rect Rect2U sourceRect; Rect2U textureRect; outLine.Clear(); RETURN_NULL_IF_FALSE(ReadLineToValues(stream, outLine, outValues)); region->SetName(outValues[0]); region->SetRotate(StringParser::StringTo<bool>(outValues[1])); sourceRect.Origin.X = StringParser::StringTo<uint>(outValues[2]); sourceRect.Origin.Y = StringParser::StringTo<uint>(outValues[3]); sourceRect.Size.Width = StringParser::StringTo<uint>(outValues[4]); sourceRect.Size.Height = StringParser::StringTo<uint>(outValues[5]); textureRect.Origin.X = StringParser::StringTo<uint>(outValues[6]); textureRect.Origin.Y = StringParser::StringTo<uint>(outValues[7]); textureRect.Size.Width = StringParser::StringTo<uint>(outValues[8]); textureRect.Size.Height = StringParser::StringTo<uint>(outValues[9]); region->SetSourceRect(sourceRect); region->SetTextureRect(textureRect); return region.release(); }
size_t IStream::ReadDataToString(HeapString& outString, int readCount/*=0*/, bool withNullTermitated /*= false*/)const { RETURN_ZERO_IF_FALSE(CanRead()); uintp readSize = 0; if (readCount == 0) { readSize = Math::Min(outString.LeftLength(), LeftLength()); } else if (readCount < 0) { readSize = LeftLength(); outString.ReserveLeftLength(readSize); } else { readSize = Math::Min((size_t)readCount, LeftLength()); outString.ReserveLeftLength(readSize); } MemoryData outData = MemoryData::FromStatic((const byte*)outString.LeftPtr(), readSize); size_t count = ReadDataTo(outData, DataReadingMode::AlwaysCopy); if (withNullTermitated) { --count; } outString.ForceAppendLength(count); return count; }
size_t IStream::ReadAllLinesTo(List<HeapString>& outLines, size_t maxCount/*=1024*/, bool isTrim/*=true*/, bool ignoreEmptyLine/*=true*/)const { size_t count = 0; HeapString temp; temp.ReserveLength(maxCount); while (true) { temp.Clear(); size_t readCount = ReadLineToString(temp); count += readCount; BREAK_IF_ZERO(readCount); if (ignoreEmptyLine) { CONTINUE_IF_EMPTY(temp); } if (isTrim) { temp.TrimAll(); } outLines.Add(temp); temp.ForceSetLength(0); } return count; }
ScriptObject* ScriptModule::NewObjectWithInt(StringRef className, int address) { asIObjectType* scriptObjectType = mScriptModule->GetObjectTypeByName(className.c_str()); if (scriptObjectType == nullptr) { Log::FormatError("Cannot find class by {}", className.c_str()); } RETURN_NULL_IF_NULL(scriptObjectType); HeapString factoryName = className; factoryName += "@ "; factoryName += className; factoryName += "(int address)"; asIScriptFunction* factory = scriptObjectType->GetFactoryByDecl(factoryName.c_str()); if (factory == nullptr) { Log::FormatError("Cannot find class factory by {}", factoryName.c_str()); } RETURN_NULL_IF_NULL(factory); asIScriptContext* context = ScriptEngine::Instance().GetScriptContext(); context->Prepare(factory); context->SetArgDWord(0, address); context->Execute(); asIScriptObject* scriptObject = *(asIScriptObject**)context->GetAddressOfReturnValue(); return new ScriptObject(scriptObject); }
void EffectRenderGroup::Print(HeapString& ioStr, uint level) { ioStr.Append('\t', level); ioStr.AppendLine(mEffect->Name().c_str()); for (auto materialRenderList : mGroups) { materialRenderList->Print(ioStr, level + 1); } }
size_t HashStream::ReadStringTo(HeapString& outString)const { size_t oldPos = outString.Length(); size_t readCount = mSourceStream->ReadStringTo(outString); RETURN_ZERO_IF_ZERO(readCount); mHasher->Process(outString.c_str() + oldPos, outString.Length() - oldPos); return readCount; }
void IRenderQueue::PrintRenderQueue(const RenderableNodeList& nodes) { HeapString testStr; size_t count = nodes.Count(); FOR_EACH_SIZE(i, count) { IRenderable* node = (IRenderable*)nodes[i]; testStr.AppendFormat("{}:{}:{}\n", node->Id(), node->Material()->Name().c_str(), node->Name().c_str()); }
size_t HashStream::ReadLineToString(HeapString& outString, bool includeNewLine/*=true*/)const { size_t oldPos = outString.Length(); size_t readCount = mSourceStream->ReadLineToString(outString, includeNewLine); RETURN_ZERO_IF_ZERO(readCount); mHasher->Process(outString.c_str() + oldPos, (outString.Length() - oldPos)*sizeof(char)); return readCount; }
void BaseBufferRenderBatch::PrintNodes()const { HeapString testStr; for (auto node : mNodes) { testStr.AppendFormat("{},", node->Name().c_str()); } Log::Info(testStr); }
HeapString HeapString::FormatV(const char* format, va_list args) { int len = 0; trio_vcprintf(CountAnsiHeapString, &len, format, args); HeapString dest; dest.AllocBuffer(len); trio_vsnprintf(dest.m_string, len + 1, format, args); return dest; }
bool EventLoopThreadPool::Start(uint threadCount, const StringRef& pollerName) { HeapString threadName; FOR_EACH_SIZE(i, threadCount) { threadName.Format("EventLoopThread-{}", i); EventLoopThread* thread = new EventLoopThread(threadName, pollerName); mThreads.Add(thread); thread->Start(); }
PublishTarget PublishTarget::Parse(StringRef fileName) { if (!fileName.Contains('-')) { return MatchAll; } HeapString rawName = Path::GetFileNameWithoutExtension(fileName); rawName.RemoveBeginExclude('-'); if (rawName.IsEmpty()) { return MatchAll; } List<HeapString> outResults; StringParser::Split<char>(rawName, "-", outResults); if (outResults.IsEmpty()) { return MatchAll; } int resultTag = 0; FOR_EACH_COLLECTION(i, outResults) { const HeapString& str = *i; int* tempTag = mTagDict.TryGetValue(str); if (tempTag != nullptr) { resultTag |= *tempTag; } else if (!StdString::IsDigit(str.c_str())) { Log::FormatError("Invalid tag:{}", str.c_str()); } } PublishTarget tag = PublishTarget(resultTag); if (tag.Version == PublishVersions::None) { tag.Version = PublishVersions::All; } if (tag.Device == PublishDevices::None) { tag.Device = PublishDevices::All; } if (tag.Language == PublishLanguages::None) { tag.Language = PublishLanguages::All; } return tag; }
void SceneRenderGroup::Print(HeapString& ioStr, uint level) { ioStr.AppendLine(); ioStr.Append('\t', level); for (auto group : mGroups) { group->Print(ioStr, level + 1); } Log::Info(ioStr); }
HeapString Matrix3::ToString() const { /* [11,12,13] [21,22,23] [31,32,33] */ HeapString result; result.Format("[{},{},{}]\n[{},{},{}]\n[{},{},{}]",M11,M12,M13,M21,M22,M23,M31,M32,M33); return result; }
HeapString HeapString::TrimLeft(const char* trimChars) const { HeapString dest; // Count trim characters. size_t trimCharsLen = 0; const char empty[] = { 0 }; for (const char* ptr = trimChars ? trimChars : empty; *ptr; ++ptr, ++trimCharsLen) { } const char* str = m_string; if (trimCharsLen == 0) { while (isspace(*str)) str++; } else { if (trimCharsLen == 1) { while (*str == *trimChars) str++; } else { const char* stringEnd = m_string + GetStringData()->stringLen; const char* lastStr = str; while (str != stringEnd) { for (const char* ptr = trimChars; *ptr; ++ptr) { if (*ptr == *str) { str++; break; } } if (lastStr == str) break; lastStr = str; } } } size_t count = GetStringData()->stringLen - (str - m_string); if (count > 0) { dest.AllocBuffer(count); memcpy(dest.m_string, str, count); } return dest; }
HeapString HeapString::Sub(size_t startPos, size_t count) const { size_t stringLen = GetStringData()->stringLen; if (startPos > stringLen || count == 0) return HeapString(); if (startPos + count > stringLen) count = stringLen - startPos; HeapString dest; dest.AllocBuffer(count); memcpy(dest.m_string, m_string + startPos, count * sizeof(char)); return dest; }
bool SirenTextParser::ParseFile(const FileIdRef& fileId) { HeapString text = FileSystem::Instance().ReadAllText(fileId); if (text.IsEmpty()) { Log::FormatError("Cannot find file:{}", fileId.Name); return false; } Preprocess(text); StringRef proto = text; return Parse(proto); }
TextureAtlasPage* MedusaTextureAtlas::OnCreatePage(const FileIdRef& fileId, const IStream& stream) { HeapString outLine; List<HeapString> outValues; std::unique_ptr<TextureAtlasPage> page(new TextureAtlasPage(0)); page->SetTexcoordUpSide(false); outLine.Clear(); RETURN_NULL_IF_FALSE(ReadLineToValues(stream, outLine, outValues)); FileId textureFileId = FileId::ParseFrom(outValues[0]); page->SetTextureFileId(textureFileId); Size2U pageSize; pageSize.Width = (uint)outValues[1].ToInt(); pageSize.Height = (uint)outValues[2].ToInt(); page->SetPageSize(pageSize); //ignore format,use real image format instead //outValues[3] //read filter if (outValues[4] == "NearestNeighbour") { page->SetMagFilter(GraphicsTextureMagFilter::Nearest); page->SetMinFilter(GraphicsTextureMinFilter::Nearest); } else// if (outLine == "Linear") { page->SetMagFilter(GraphicsTextureMagFilter::Linear); page->SetMinFilter(GraphicsTextureMinFilter::Linear); } page->SetFlipPVR(StringParser::StringTo<bool>(outValues[5])); page->SetPremultiplyAlpha(StringParser::StringTo<bool>(outValues[6])); //read regions TextureAtlasRegion* region = nullptr; do { region = CreateAtlasRegion(stream); if (region != nullptr) { page->AddRegion(region); } } while (region != nullptr); return page.release(); }
void Launcher::UpdateItemCount(const uint count) const { if (count == 0 || count == 1) { menu[IDM_LAUNCHER_EDIT_FIND].Enable( count ); menu[IDM_LAUNCHER_EDIT_CLEAR].Enable( count ); } static HeapString form( HeapString() << ' ' << Resource::String(IDS_TEXT_FILES) << ": " ); const uint length = form.Length(); statusBar.Text(StatusBar::SECOND_FIELD) << (form << count).Ptr(); form.ShrinkTo( length ); }
HeapString HeapString::Format(const char* format, ...) { va_list args; va_start(args, format); int len = 0; trio_vcprintf(CountAnsiHeapString, &len, format, args); HeapString dest; dest.AllocBuffer(len); trio_vsnprintf(dest.m_string, len + 1, format, args); va_end(args); return dest; }
HeapString HeapString::TrimRight(const char* trimChars) const { HeapString dest; // Count trim characters. size_t trimCharsLen = 0; const char empty[] = { 0 }; for (const char* ptr = trimChars ? trimChars : empty; *ptr; ++ptr, ++trimCharsLen) { } size_t stringLen = GetStringData()->stringLen; char* str = (char*)m_string + stringLen - 1; if (trimCharsLen == 0) { while (str != m_string && isspace(*str)) str--; } else { if (trimCharsLen == 1) { while (str != m_string && *str == *trimChars) str--; } else { const char* lastStr = str; while (str != m_string) { for (const char* ptr = trimChars; *ptr; ++ptr) { if (*ptr == *str) { str--; break; } } if (lastStr == str) break; lastStr = str; } } } size_t count = str - m_string + 1; dest.AllocBuffer(count); memcpy(dest.m_string, m_string, count); return dest; }
bool BaseCaseLayer::Initialize() { RETURN_FALSE_IF_FALSE(ILayer::Initialize()); HeapString title = Class().Name(); title.RemoveLast("Layer"); ILabel* label = NodeFactory::Instance().CreateSingleLineLabel(FontId("arial22.fnt"), title, Alignment::LeftBottom, Size2U::Zero, true); label->SetDock(DockPoint::MiddleTop); label->SetAnchorPoint(AnchorPoint::MiddleTop); label->SetLogicZ(9999); AddChild(label); return true; }
intp StringParser::ConvertToBuffer(const wchar_t* str, size_t length, HeapString& outBuffer) { outBuffer.Clear(); if (length == 0) { return 0; } constexpr bool isUTF16 = sizeof(wchar_t) == 2; if (isUTF16) { //sizeof(wchar_t)==2 size_t utf8Size = length * 3 + 1; outBuffer.ReserveSize(utf8Size); const UTF16* sourceStart = reinterpret_cast<const UTF16*>(str); const UTF16* sourceEnd = sourceStart + length; UTF8* targetStart = reinterpret_cast<UTF8*>(outBuffer.MutableBuffer()); UTF8* targetEnd = targetStart + utf8Size; ConversionResult res = ConvertUTF16toUTF8(&sourceStart, sourceEnd, &targetStart, targetEnd, strictConversion); *targetStart = 0; if (res == conversionOK) { intp count = targetStart - reinterpret_cast<UTF8*>(outBuffer.MutableBuffer()); outBuffer.ForceSetLength(count); return count; } } else { //sizeof(wchar_t)==4 size_t utf8Size = length * 4 + 1; outBuffer.ReserveSize(utf8Size); const UTF32* sourceStart = reinterpret_cast<const UTF32*>(str); const UTF32* sourceEnd = sourceStart + length; UTF8* targetStart = reinterpret_cast<UTF8*>(outBuffer.MutableBuffer()); UTF8* targetEnd = targetStart + utf8Size; ConversionResult res = ConvertUTF32toUTF8(&sourceStart, sourceEnd, &targetStart, targetEnd, strictConversion); *targetStart = 0; if (res == conversionOK) { intp count = targetStart - reinterpret_cast<UTF8*>(outBuffer.MutableBuffer()); outBuffer.ForceSetLength(count); return count; } } return 0; }
HeapString HeapString::Replace(char oldCh, char newCh) const { HeapString dest; dest.AllocBuffer(GetStringData()->stringLen); char* destPtr = dest.m_string; for (char* srcPtr = m_string; *srcPtr; ++srcPtr, ++destPtr) { char ch = *srcPtr; if (ch == oldCh) *destPtr = newCh; else *destPtr = ch; } return dest; }
ScriptObject* ScriptModule::NewObject(StringRef className) { asIObjectType* scriptObjectType = mScriptModule->GetObjectTypeByName(className.c_str()); RETURN_NULL_IF_NULL(scriptObjectType); HeapString factoryName = className; factoryName += "@ "; factoryName += className; factoryName += "()"; asIScriptFunction* factory = scriptObjectType->GetFactoryByDecl(factoryName.c_str()); RETURN_NULL_IF_NULL(factory); asIScriptContext* context = ScriptEngine::Instance().GetScriptContext(); context->Prepare(factory); context->Execute(); asIScriptObject* scriptObject = *(asIScriptObject**)context->GetAddressOfReturnValue(); return new ScriptObject(scriptObject); }
bool File::ReadAllTextTo(StringRef filePath, HeapString& outString) { FileStream reader(filePath, FileOpenMode::ReadOnly, FileDataType::Text); if (reader.IsOpen()) { outString.ReserveLength(reader.Length()); reader.ReadStringTo(outString); return true; } return false; }
void SirenTextParser::Preprocess(HeapString& text) { //trim //remove all comment intp beginIndex = text.Length() - 1; while (true) { beginIndex = text.LastIndexOf("//", 0, beginIndex); if (beginIndex >= 0) { intp endIndex = text.IndexOfAny(StdString::ConstValues<char>::NewLineChars, beginIndex + 2); if (endIndex >= 0) { text.RemoveAt(beginIndex, endIndex - beginIndex); } } else { return; } } }
int ListView::Add(GenericString text,const LPARAM data,const bool checked) const { HeapString tmp; LVITEM lvItem; if (text.Length()) { if (text.NullTerminated()) { lvItem.pszText = const_cast<wchar_t*>(text.Ptr()); } else { tmp = text; lvItem.pszText = tmp.Ptr(); } } else { lvItem.pszText = LPSTR_TEXTCALLBACK; } lvItem.mask = LVIF_TEXT; if (data) lvItem.mask |= LVIF_PARAM; lvItem.iItem = INT_MAX; lvItem.iSubItem = 0; lvItem.lParam = data; const int index = ListView_InsertItem( control, &lvItem ); if (checked) ListView_SetCheckState( control, index, true ); return index; }