1 // textprocessing.cpp - Text processing subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
24 #include "textprocessing.h"
26 void EscapeString(wxString *ReceivedString, bool StripQuotes)
29 // Escape a string that contains escapable characters.
31 ReceivedString->Replace(wxT("\\"), wxT("\\\\"), TRUE);
32 ReceivedString->Replace(wxT(","), wxT("\\,"), TRUE);
33 ReceivedString->Replace(wxT(";"), wxT("\\;"), TRUE);
34 ReceivedString->Replace(wxT("\r\n"), wxT("\\n"), TRUE);
35 ReceivedString->Replace(wxT("\n"), wxT("\\n"), TRUE);
37 if (StripQuotes == TRUE){
39 ReceivedString->Replace(wxT("\""), wxT(""), TRUE);
45 void GetEscapeString(wxTextCtrl *TextCtrl, wxString *ProcessString, bool StripQuotes)
48 // Get an escaped string from a wxTextCtrl.
50 *ProcessString = TextCtrl->GetValue();
51 EscapeString(ProcessString, StripQuotes);
55 void GetEscapeString(wxComboBox *ComboCtrl, wxString *ProcessString, bool StripQuotes)
58 // Get an escaped string from a wxComboBox.
60 *ProcessString = ComboCtrl->GetValue();
61 EscapeString(ProcessString, StripQuotes);
65 void GetEscapeString(wxChoice *ChoiceCtrl, wxString *ProcessString, bool StripQuotes)
68 // Get an escaped string from a wxChoice.
70 *ProcessString = ChoiceCtrl->GetString(ChoiceCtrl->GetSelection());
71 EscapeString(ProcessString, StripQuotes);
75 void CaptureString(wxString *ProcessString, bool StripQuotes)
78 // Capture a string for processing.
80 ProcessString->Replace(wxT("\\n"), wxT("\n"), TRUE);
81 ProcessString->Replace(wxT("\\;"), wxT(";"), TRUE);
82 ProcessString->Replace(wxT("\\,"), wxT(","), TRUE);
83 ProcessString->Replace(wxT("\\\\"), wxT("\\"), TRUE);
85 if (StripQuotes == TRUE){
87 ProcessString->Replace(wxT("\""), wxT(""), TRUE);
93 void ResetUnusedString(wxString *ProcessString)
96 // Reset an unused string.
98 ProcessString->Replace(wxT("\\\\"), wxT("\\"), TRUE);
99 ProcessString->Replace(wxT("\\n"), wxT("\n"), TRUE);
100 ProcessString->Replace(wxT("\\;"), wxT(";"), TRUE);
101 ProcessString->Replace(wxT("\\,"), wxT(","), TRUE);
105 void ConvertToHTML(wxString *ProcessString)
108 // Convert string into text that can be used with a
111 ProcessString->Replace(wxT("&"), wxT("&"), TRUE);
112 ProcessString->Replace(wxT("<"), wxT("<"), TRUE);
113 ProcessString->Replace(wxT(">"), wxT(">"), TRUE);
114 ProcessString->Replace(wxT("\n"), wxT("<br>"), TRUE);
118 void DeleteMapDataProcess(int IndexNum, std::map<int, std::string>* MapData){
120 // Delete map data (for map<int,string>).
122 MapData->erase(IndexNum);
126 void DeleteMapDataProcess(int IndexNum, std::map<int, wxString>* MapData){
128 // Delete map data (for map<int,wxString>).
130 MapData->erase(IndexNum);
134 void DeleteMapDataProcess(int IndexNum, std::map<int, int>* MapData){
136 // Delete map data (for map<int,int>).
138 MapData->erase(IndexNum);
142 void DeleteMapDataProcess(int IndexNum, std::map<int, bool>* MapData){
144 // Delete map data (for map<int,bool>).
146 MapData->erase(IndexNum);
150 bool MapDataExists(int *ItemIndex, std::map<int,wxString> *MapPtr){
152 // Check if map data exists (for map<int,wxString>).
154 if (MapPtr->find(*ItemIndex) == MapPtr->end()){
166 bool MapDataExists(int *ItemIndex, std::map<int,int> *MapPtr){
168 // Check if map data exists (for map<int,int>).
170 if (MapPtr->find(*ItemIndex) == MapPtr->end()){
182 wxString OutputText(wxString *TextInput){
184 wxString OutputTextData;
188 int MaxLineSeek = 77;
190 for (CharSeek = 0; CharSeek < TextInput->size(); CharSeek++){
194 if (LineSeek == MaxLineSeek){
196 if (TextInput->substr(CharSeek, 1) != "\n"){
197 OutputLine += TextInput->substr(CharSeek, 1);
200 OutputTextData += OutputLine;
208 OutputLine += TextInput->substr(CharSeek, 1);
212 if (OutputLine != " " && OutputLine != " \n"){
214 OutputTextData += OutputLine;
218 return OutputTextData;