void PrintDoc(seakgOutput *pOutput, UnicodeString filename, UnicodeString name, UnicodeString uuid, UnicodeString code) { filename = filename.SubString(rootPath.Length()+1, filename.Length() - rootPath.Length()); UnicodeString id = ""; // UnicodeString id = ""; code = encoding_html(code); name = encoding_html(name); TGUID g; OleCheck(CoCreateGuid(&g)); //Sysutils::GUIDToString(g); //id = Sysutils::GUIDToString(g); //id = id.SubString(2,37) + "[" + IntToStr(g_nInc++) + "]"; id = IntToStr(g_nInc++); while (id.Length() < 6) id = "0" + id; id = prefixforid + id; pOutput->addline("\t<doc>"); pOutput->addline("\t\t<field name=\"id\">" + id + "</field>"); pOutput->addline("\t\t<field name=\"project\">" + projectName + "</field>"); pOutput->addline("\t\t<field name=\"name\">" + name + "</field>"); pOutput->addline("\t\t<field name=\"uuid\">" + uuid.UpperCase() + "</field>"); pOutput->addline("\t\t<field name=\"source_filepath\">" + filename + "</field>"); pOutput->addline("\t\t<field name=\"full_source_code\">\n" + code + "\n\t\t</field>"); pOutput->addline("\t</doc>"); };
//--------------------------------------------------------------------------- void __fastcall TRightsFrame::SetText(UnicodeString value) { if (Text != value) { UnicodeString RightsStr = value; int P = RightsStr.LowerCase().Pos(FAddXToDirectoriesSuffix); bool AAddXToDirectories = (P > 0); if (AAddXToDirectories) { RightsStr.Delete(P, FAddXToDirectoriesSuffix.Length()); } RightsStr = DeleteChar(DeleteChar(RightsStr, L'('), L')').Trim(); TRights R = Rights; if (((RightsStr.Length() == 3) || (RightsStr.Length() == 4)) && IsNumber(RightsStr)) { R.Octal = RightsStr; } else { R.Text = RightsStr; } Rights = R; AddXToDirectories = AAddXToDirectories; } }
//--------------------------------------------------------------------------- void TFileMasks::TrimEx(UnicodeString & Str, intptr_t & Start, intptr_t & End) { UnicodeString Buf = TrimLeft(Str); Start += Str.Length() - Buf.Length(); Str = TrimRight(Buf); End -= Buf.Length() - Str.Length(); }
void AppendPathDelimiterW(UnicodeString & Str) { if (!Str.IsEmpty() && Str[Str.Length()] != L'/' && Str[Str.Length()] != L'\\') { Str += L"\\";; } }
//--------------------------------------------------------------------------- UnicodeString MaskFileName(const UnicodeString & FileName, const UnicodeString & Mask) { UnicodeString Result = FileName; if (IsEffectiveFileNameMask(Mask)) { bool Masked; intptr_t P = Mask.LastDelimiter(L"."); if (P > 0) { intptr_t P2 = Result.LastDelimiter("."); // only dot at beginning of file name is not considered as // name/ext separator UnicodeString FileExt = P2 > 1 ? Result.SubString(P2 + 1, Result.Length() - P2) : UnicodeString(); FileExt = MaskFilePart(FileExt, Mask.SubString(P + 1, Mask.Length() - P), Masked); if (P2 > 1) { Result.SetLength(P2 - 1); } Result = MaskFilePart(Result, Mask.SubString(1, P - 1), Masked); if (!FileExt.IsEmpty()) { Result += L"." + FileExt; } } else { Result = MaskFilePart(Result, Mask, Masked); } } return Result; }
UnicodeString TStrings::GetTextStr() const { UnicodeString Result; intptr_t Count = GetCount(); intptr_t Size = 0; UnicodeString LB = sLineBreak; for (intptr_t I = 0; I < Count; I++) { Size += GetString(I).Length() + LB.Length(); } Result.SetLength(Size); wchar_t * P = const_cast<wchar_t *>(Result.c_str()); for (intptr_t I = 0; I < Count; I++) { UnicodeString S = GetString(I); intptr_t L = S.Length() * sizeof(wchar_t); if (L != 0) { memmove(P, S.c_str(), L); P += S.Length(); } L = LB.Length() * sizeof(wchar_t); if (L != 0) { memmove(P, LB.c_str(), L); P += LB.Length(); } } return Result; }
//--------------------------------------------------------------------- void __fastcall TFileSystemInfoDialog::ClipboardAddItem(TControl * Control, int Label, UnicodeString Value) { if (Control->Enabled && !Value.IsEmpty()) { if (FLastFeededControl != Control) { if (FLastFeededControl != NULL) { FClipboard += UnicodeString::StringOfChar(L'-', 60) + L"\r\n"; } FLastFeededControl = Control; } if (dynamic_cast<TListView *>(Control) == NULL) { TGroupBox * Group = dynamic_cast<TGroupBox *>(Control->Parent); assert(Group != NULL); if ((Value.Length() >= 2) && (Value.SubString(Value.Length() - 1, 2) == L"\r\n")) { Value.SetLength(Value.Length() - 2); } FClipboard += FORMAT(L"%s\r\n%s\r\n", (Group->Caption, Value)); } else { assert(dynamic_cast<TListView *>(Control) != NULL); FClipboard += FORMAT(L"%s = %s\r\n", (LoadStr(Label), Value)); } } }
UnicodeString FileSearch(const UnicodeString & FileName, const UnicodeString & DirectoryList) { UnicodeString Temp; UnicodeString Result; Temp = DirectoryList; UnicodeString PathSeparators = L"/\\"; do { intptr_t I = ::Pos(Temp, PathSeparators); while ((Temp.Length() > 0) && (I == 0)) { Temp.Delete(1, 1); I = ::Pos(Temp, PathSeparators); } I = ::Pos(Temp, PathSeparators); if (I > 0) { Result = Temp.SubString(1, I - 1); Temp.Delete(1, I); } else { Result = Temp; Temp = L""; } Result = ::IncludeTrailingBackslash(Result); Result = Result + FileName; if (!::FileExists(Result)) { Result = L""; } } while (!(Temp.Length() == 0) || (Result.Length() != 0)); return Result; }
//--------------------------------------------------------------------------- UnicodeString __fastcall TConfiguration::TrimVersion(UnicodeString Version) { while ((Version.Pos(L".") != Version.LastDelimiter(L".")) && (Version.SubString(Version.Length() - 1, 2) == L".0")) { Version.SetLength(Version.Length() - 2); } return Version; }
void TOptions::Add(const UnicodeString & Value) { if (!FNoMoreSwitches && (Value.Length() == 2) && (Value[1] == Value[2]) && (FSwitchMarks.Pos(Value[1]) > 0)) { FNoMoreSwitches = true; } else { bool Switch = false; intptr_t Index = 0; // shut up if (!FNoMoreSwitches && (Value.Length() >= 2) && (FSwitchMarks.Pos(Value[1]) > 0)) { Index = 2; Switch = true; while (Switch && (Index <= Value.Length())) { if (Value.IsDelimiter(FSwitchValueDelimiters, Index)) { break; } // this is to treat /home/martin as parameter, not as switch else if ((Value[Index] != L'?') && !IsLetter(Value[Index])) { Switch = false; break; } ++Index; } } if (Switch) { TOption Option; Option.Type = otSwitch; Option.Name = Value.SubString(2, Index - 2); Option.Value = Value.SubString(Index + 1, Value.Length()); Option.Used = false; FOptions.push_back(Option); } else { TOption Option; Option.Type = otParam; Option.Value = Value; Option.Used = false; FOptions.push_back(Option); ++FParamCount; } } FOriginalOptions = FOptions; }
//--------------------------------------------------------------------------- void TFileMasks::SetStr(const UnicodeString & Str, bool SingleMask) { UnicodeString Backup = FStr; try { FStr = Str; Clear(); intptr_t NextMaskFrom = 1; bool Include = true; while (NextMaskFrom <= Str.Length()) { intptr_t MaskStart = NextMaskFrom; wchar_t NextMaskDelimiter; UnicodeString MaskStr; if (SingleMask) { MaskStr = Str; NextMaskFrom = Str.Length() + 1; NextMaskDelimiter = L'\0'; } else { MaskStr = CopyToChars(Str, NextMaskFrom, AllFileMasksDelimiters, false, &NextMaskDelimiter, true); } intptr_t MaskEnd = NextMaskFrom - 2; TrimEx(MaskStr, MaskStart, MaskEnd); if (!MaskStr.IsEmpty()) { CreateMask(MaskStr, MaskStart, MaskEnd, Include); } if (NextMaskDelimiter == IncludeExcludeFileMasksDelimiter) { if (Include) { Include = false; } else { ThrowError(NextMaskFrom - 1, Str.Length()); } } } } catch(...) { // this does not work correctly if previous mask was set using SetMask. // this should not fail (the mask was validated before), // otherwise we end in an infinite loop SetStr(Backup, false); throw; } }
UnicodeString IncludeTrailingBackslash(const UnicodeString & Str) { UnicodeString Result = Str; if ((Str.Length() == 0) || ((Str[Str.Length()] != L'/') && (Str[Str.Length()] != L'\\'))) { Result += L'\\'; } return Result; }
UnicodeString ExcludeTrailingBackslash(const UnicodeString & Str) { UnicodeString Result = Str; if ((Str.Length() > 0) && ((Str[Str.Length()] == L'/') || (Str[Str.Length()] == L'\\'))) { Result.SetLength(Result.Length() - 1); } return Result; }
//--------------------------------------------------------------------------- UnicodeString TConfiguration::TrimVersion(const UnicodeString & Version) const { UnicodeString Result = Version; while ((Result.Pos(L".") != Result.LastDelimiter(L".")) && (Result.SubString(Result.Length() - 1, 2) == L".0")) { Result.SetLength(Result.Length() - 2); } return Result; }
UnicodeString ReplaceStrAll(const UnicodeString & Str, const UnicodeString & What, const UnicodeString & ByWhat) { UnicodeString Result = Str; intptr_t Pos = Result.Pos(What); while (Pos > 0) { Result.Replace(Pos, What.Length(), ByWhat.c_str(), ByWhat.Length()); Pos = Result.Pos(What); } return Result; }
//--------------------------------------------------------------------------- UnicodeString StrToHex(const UnicodeString & Str, bool UpperCase, char Separator) { UnicodeString Result; for (intptr_t I = 1; I <= Str.Length(); I++) { Result += CharToHex(static_cast<char>(Str[I]), UpperCase); if ((Separator != L'\0') && (I <= Str.Length())) { Result += Separator; } } return Result; }
//--------------------------------------------------------------------------- intptr_t FirstDelimiter(const UnicodeString & Delimiters, const UnicodeString & Str) { if (Str.Length()) { for (intptr_t I = 1; I <= Str.Length(); ++I) { if (Str.IsDelimiter(Delimiters, I)) { return I; } } } return 0; }
bool TForm1::VarMi(UnicodeString bunda1, UnicodeString bundan1) { char* bunda = AnsiString(bunda1).c_str(); char* bundan = AnsiString(bundan1).c_str(); for (int i = 0; i < bunda1.Length(); i++) { for (int j = 0; j < bundan1.Length(); j++) { if (bunda[i] == bundan[j]) return true; } } return false; }
//--------------------------------------------------------------------------- intptr_t LastDelimiter(const UnicodeString & Delimiters, const UnicodeString & Str) { if (Str.Length()) { for (intptr_t I = Str.Length(); I >= 1; --I) { if (Str.IsDelimiter(Delimiters, I)) { return I; } } } return 0; }
UnicodeString getName(UnicodeString str) { UnicodeString name = str; if (name.Pos(":") > 0) name = name.SubString(1, name.Pos(":")-1); UnicodeString alphabet = L"QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890_"; while (true) { if (name.Length() == 0) break; UnicodeString ch = name.SubString(name.Length(), 1); if (alphabet.Pos(ch) > 0 && name.Length() > 0) break; name = name.SubString(1, name.Length()-1); } UnicodeString temp_name; while (true) { if (name.Length() == 0) break; UnicodeString ch = name.SubString(name.Length(), 1); if (alphabet.Pos(ch) > 0 && name.Length() > 0) temp_name = ch + temp_name; else break; name = name.SubString(1, name.Length()-1); } return temp_name; }
bool IsDelimiter(const UnicodeString & Delimiters, const UnicodeString & Str, intptr_t Index) { if (Index <= Str.Length()) { wchar_t Ch = Str[Index]; for (intptr_t I = 1; I <= Delimiters.Length(); I++) { if (Delimiters[I] == Ch) { return true; } } } return false; }
//--------------------------------------------------------------------------- UnicodeString TFileMasks::ComposeMaskStr( TStrings * MasksStr, bool Directory) { UnicodeString Result; UnicodeString ResultNoDirMask; for (intptr_t I = 0; I < MasksStr->GetCount(); ++I) { UnicodeString Str = MasksStr->GetString(I).Trim(); if (!Str.IsEmpty()) { for (intptr_t P = 1; P <= Str.Length(); P++) { if (Str.IsDelimiter(AllFileMasksDelimiters, P)) { Str.Insert(Str[P], P); P++; } } UnicodeString StrNoDirMask; if (Directory) { StrNoDirMask = Str; Str = MakeDirectoryMask(Str); } else { while (Str.IsDelimiter(DirectoryMaskDelimiters, Str.Length())) { Str.SetLength(Str.Length() - 1); } StrNoDirMask = Str; } AddToList(Result, Str, FileMasksDelimiterStr); AddToList(ResultNoDirMask, StrNoDirMask, FileMasksDelimiterStr); } } // For directories, the above will add slash ay the end of masks, // breaking size and time masks and thus circumverting their validation. // This performes as hoc validation to cover the scenario. // For files this makes no difference, but no harm either TFileMasks Temp(Directory ? 1 : 0); Temp = ResultNoDirMask; return Result; }
//--------------------------------------------------------------------------- void TCustomCommand::GetToken( const UnicodeString & Command, intptr_t Index, intptr_t & Len, wchar_t & PatternCmd) { assert(Index <= Command.Length()); const wchar_t * Ptr = Command.c_str() + Index - 1; if (Ptr[0] == L'!') { PatternCmd = Ptr[1]; if (PatternCmd == L'\0') { Len = 1; } else if (PatternCmd == L'!') { Len = 2; } else { Len = PatternLen(Command, Index); } if (Len <= 0) { throw Exception(FMTLOAD(CUSTOM_COMMAND_UNKNOWN, PatternCmd, Index)); } else { if ((Command.Length() - Index + 1) < Len) { throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, PatternCmd, Index)); } } } else { PatternCmd = TEXT_TOKEN; const wchar_t * NextPattern = wcschr(Ptr, L'!'); if (NextPattern == nullptr) { Len = Command.Length() - Index + 1; } else { Len = NextPattern - Ptr; } } }
//--------------------------------------------------------------------------- void AppendWChar(UnicodeString & Str, const wchar_t Ch) { if (!Str.IsEmpty() && Str[Str.Length()] != Ch) { Str += Ch; } }
//--------------------------------------------------------------------------- void TMain::ColorLog(UnicodeString token) { int pos = 0; int foundAt = m_log->FindText(token,pos,m_log->Text.Length(),TSearchTypes()); while(foundAt!=-1) { m_log->SelStart = foundAt; m_log->SelLength = token.Length(); m_log->SelAttributes->Color = (TColor)0x00FF0080; pos = foundAt + token.Length(); foundAt = m_log->FindText(token,pos,m_log->Text.Length(),TSearchTypes()); } m_log->SelStart = m_log->Text.Length(); }
BOOST_FIXTURE_TEST_CASE(test19, base_fixture_t) { UnicodeString ProgramsFolder; ::SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder); BOOST_TEST_MESSAGE("ProgramsFolder = " << W2MB(ProgramsFolder.c_str()).c_str()); BOOST_CHECK(ProgramsFolder.Length() > 0); }
static void tokenize(const UnicodeString & str, rde::vector<UnicodeString> & tokens, const UnicodeString & delimiters = L" ", const bool trimEmpty = false) { intptr_t lastPos = 0; while (true) { intptr_t pos = str.FindFirstOf(delimiters.c_str(), lastPos); if (pos == NPOS) { pos = str.Length(); if (pos != lastPos || !trimEmpty) { tokens.push_back( UnicodeString(str.data() + lastPos, pos - lastPos)); } break; } else { if (pos != lastPos || !trimEmpty) { tokens.push_back( UnicodeString(str.data() + lastPos, pos - lastPos)); } } lastPos = pos + 1; } }
//--------------------------------------------------------------------------- bool TFileCustomCommand::PatternReplacement( const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit) { // keep consistent with TSessionLog::OpenLogFile if (Pattern == L"!@") { Replacement = FData.HostName; } else if (AnsiSameText(Pattern, L"!u")) { Replacement = FData.UserName; } else if (AnsiSameText(Pattern, L"!p")) { Replacement = FData.Password; } else if (Pattern == L"!/") { Replacement = UnixIncludeTrailingBackslash(FPath); } else if (Pattern == L"!&") { Replacement = FFileList; // already delimited Delimit = false; } else { assert(Pattern.Length() == 1); Replacement = FFileName; } return true; }
UnicodeString TForm1::createHyperLinkToClassification(std::vector<exlClass> &classes, int nLine) { UnicodeString name = classes[nLine].Name; UnicodeString name2 = ""; for (int i = 1; i < name.Length()+1; i++) { if (name[i] == '"') { name2 += "\"\""; } else { name2 += name[i]; } } UnicodeString class_ = classes[nLine].Class; UnicodeString class2_ = ""; for (int i = 1; i < class_.Length()+1; i++) { if (class_[i] == '"') { class2_ += "\"\""; } else { class2_ += class_[i]; } } UnicodeString sLine = IntToStr(nLine + 2); UnicodeString strResult = "=ГИПЕРССЫЛКА(\"#'классификации'!A" + sLine + ":B" + sLine + "\", \"" + class2_ + ": " + name2 + "\")"; return strResult; };
UnicodeString UpperCase(const UnicodeString & Str) { std::wstring Result(Str.c_str(), Str.Length()); // Result.SetLength(Str.Length()); std::transform(Result.begin(), Result.end(), Result.begin(), ::toupper); return Result; }