📄 eccstring.cpp
字号:
/* ==========================================================================
Ecc - Erik's Code Collection
Copyright (C) 2003 - Erik Dienske
This file is part of Ecc.
Ecc is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Ecc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ecc; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
===========================================================================*/
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "EccString.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
#include <StrUtils.hpp> // AnsiReplaceStr
//---------------------------------------------------------------------------
//===========================================================================
namespace ecc {
//===========================================================================
//---------------------------------------------------------------------------
static int EccPrevMemoLinesBefore = 0;
//---------------------------------------------------------------------------
void MemoMessage(TMemo *memo, const String message,
int lines_before, int lines_after)
{
switch (lines_before)
{
case -2:
if (EccPrevMemoLinesBefore != -2) memo->Lines->Append(message);
else memo->Lines->Strings[memo->Lines->Count - 1] = message;
break;
case -1:
memo->Lines->Strings[memo->Lines->Count - 1]
= memo->Lines->Strings[memo->Lines->Count - 1] + message;
break;
default:
for (lines_before; lines_before > 0; lines_before--) memo->Lines->Append("");
memo->Lines->Append(message);
}
for (lines_after; lines_after > 0; lines_after--) memo->Lines->Append("");
MemoCursorOnLastLine(memo);
EccPrevMemoLinesBefore = lines_before;
}
//---------------------------------------------------------------------------
void MemoCursorOnLastLine(TMemo* memo)
{
memo->SelStart = memo->Lines->Text.Length() - 1;
}
//===========================================================================
//---------------------------------------------------------------------------
static int EccPrevLBLinesBefore = 0;
//---------------------------------------------------------------------------
void LBMessage(TListBox *lbox, String message,
int lines_before, int lines_after)
{
// Tabs etc. don't display very well in ListBoxes:
/* TODO : Replace \t, \n and \r with spaces? */
/* message = AnsiReplaceStr(message, "\t", " ");
message = AnsiReplaceStr(message, "\r", " ");
message = AnsiReplaceStr(message, "\n", " "); */
switch (lines_before)
{
case -2:
if (EccPrevLBLinesBefore != -2) lbox->Items->Append(message);
else lbox->Items->Strings[lbox->Count - 1] = message;
break;
case -1:
lbox->Items->Strings[lbox->Count - 1]
= lbox->Items->Strings[lbox->Count - 1] + message;
break;
default:
for (lines_before; lines_before > 0; lines_before--) lbox->Items->Append("");
lbox->Items->Append(message);
}
for (lines_after; lines_after > 0; lines_after--) lbox->Items->Append("");
LBCursorOnLastLine(lbox);
EccPrevLBLinesBefore = lines_before;
}
//---------------------------------------------------------------------------
void LBCursorOnLastLine(TListBox* lbox)
{
lbox->ItemIndex = lbox->Items->Count - 1;
lbox->ItemIndex = -1; // Unselect
}
//===========================================================================
String StripNonNumbers(String str)
{
for (int i=1; i<=str.Length(); i++)
{
if ((str[i] < '0') || (str[i] > '9')) str[i] = ' ';
}
return AnsiReplaceStr(str, " ", "");
}
//---------------------------------------------------------------------------
bool StrToBool(String bool_str)
{
return (LowerCase(bool_str) == "true") ? true : false;
}
//---------------------------------------------------------------------------
String BoolToStr(bool boolie)
{
return boolie ? "true" : "false";
}
//---------------------------------------------------------------------------
String StrToXmlQuotStr(String str)
{
str = AnsiReplaceStr(str, "\"", """);
str = AnsiReplaceStr(str, "'", "'");
return str;
}
//---------------------------------------------------------------------------
String StrToXmlUtf8Str(String str)
{
str = AnsiReplaceStr(str, "&", "&"); // Should be the first replacement! (because of the '&').
str = AnsiReplaceStr(str, "\"", """);
str = AnsiReplaceStr(str, "'", "'");
str = AnsiReplaceStr(str, "<", "<");
str = AnsiReplaceStr(str, ">", ">");
return AnsiToUtf8(str);
}
//---------------------------------------------------------------------------
String ReplaceStr(String str, String from_str, String to_str)
{
return AnsiReplaceStr(str, from_str, to_str);
}
//---------------------------------------------------------------------------
//===========================================================================
} // namespace ecc;
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -