NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
stringfunctions.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
21#include "../../kernel.hpp"
22#include "../utils/filecheck.hpp"
23#include <boost/tokenizer.hpp>
24#include <regex>
25#include <sstream>
26#include <libsha.hpp>
27
28#define DEFAULT_NUM_ARG INT_MIN
29// define the "End of transmission block" as string separator
30#define NEWSTRING (char)23
31
32using namespace std;
33
42string removeMaskedStrings(const std::string& sString)
43{
44 std::string sRet = sString;
45
46 // Go through the string and remove all relevant escape characters
47 // Omit the characters, which are identifying LaTeX command sequences
48 for (size_t i = 0; i < sRet.length(); i++)
49 {
50 if (sRet.compare(i, 2, "\\\"") == 0)
51 sRet.erase(i, 1);
52
53 if (sRet.compare(i, 2, "\\t") == 0
54 && sRet.compare(i, 4, "\\tau") != 0
55 && sRet.compare(i, 6, "\\theta") != 0
56 && sRet.compare(i, 6, "\\times") != 0)
57 sRet.replace(i, 2, "\t");
58
59 if (sRet.compare(i, 2, "\\n") == 0
60 && sRet.compare(i, 3, "\\nu") != 0)
61 sRet.replace(i, 2, "\n");
62
63 if (sRet.compare(i, 2, "\\ ") == 0)
64 sRet.erase(i + 1, 1);
65 }
66
67 return sRet;
68}
69
70
79string removeQuotationMarks(const std::string& sString)
80{
81 if (sString.find('"') == std::string::npos || sString.front() != '"' || sString.back() != '"')
82 return sString;
83
84 return sString.substr(1, sString.length() - 2);
85}
86
87
96string addQuotationMarks(const std::string& sString)
97{
98 if (sString.front() == '"' && sString.back() == '"')
99 return sString;
100 else
101 return "\"" + sString + "\"";
102}
103
104
114{
115 if (!funcArgs.sArg1.view().length())
117
118 if (funcArgs.sArg1.is_string())
119 return funcArgs.sArg1.getRef();
120
121 // Is not a string
122 return "\"" + funcArgs.sArg1.getRef() + "\"";
123}
124
125
135static std::string createLaTeXExponent(const std::string& sExp, bool negative)
136{
137 return "\\cdot10^{" + (negative ? "-"+sExp : sExp) + "}";
138}
139
140
150static std::string formatNumberToTex(const mu::value_type& number, size_t precision = 0)
151{
152 // Use the default precision if precision is default value
153 if (precision == 0)
155
156 std::string sNumber = toString(number, precision);
157
158 // Handle floating point numbers with
159 // exponents correctly
160 while (sNumber.find('e') != std::string::npos)
161 {
162 // Find first exponent start and value
163 size_t firstExp = sNumber.find('e');
164 size_t expBegin = sNumber.find_first_not_of('0', firstExp + 2);
165 size_t expEnd = sNumber.find_first_not_of("0123456789", expBegin);
166
167 // Get the modified string where the first exponent is replaced by the tex string format
168 sNumber.replace(firstExp, expEnd-firstExp,
169 createLaTeXExponent(sNumber.substr(expBegin, expEnd-expBegin), sNumber[firstExp+1] == '-'));
170 }
171
172 // Consider some special values
173 replaceAll(sNumber, "inf", "\\infty");
174 replaceAll(sNumber, "-inf", "-\\infty");
175 replaceAll(sNumber, "nan", "---");
176
177 // Return the formatted string in math mode
178 return "$" + sNumber + "$";
179}
180
181
191{
192 //funcArgs.dArg1 contains complex double to convert
193 //funcArgs.nArg1 contains precision of the conversion
194
195 // Convert the mu type to a latex string using the specified precision
196 std::string sToChar = formatNumberToTex(funcArgs.dArg1, funcArgs.nArg1 == INT_MIN ? 0 : funcArgs.nArg1);
197
198 // Return the result
199 return "\"" + sToChar + "\"";
200}
201
202
212{
213 return "\"" + toUpperCase(funcArgs.sArg1.view().to_string()) + "\"";
214}
215
216
226{
227 return "\"" + toLowerCase(funcArgs.sArg1.view().to_string()) + "\"";
228}
229
230
240{
241 if (!funcArgs.sArg1.view().length())
243
244 char* sVarValue = getenv(funcArgs.sArg1.view().to_string().c_str());
245
246 if (!sVarValue)
248 else
249 return "\"" + std::string(sVarValue) + "\"";
250}
251
252
262{
263 if (!funcArgs.sArg1.view().length())
264 return "\"\"";
265
266 std::vector<std::string> vFileParts = funcArgs.opt->getFileParts(funcArgs.sArg1.view().to_string());
267
268 StringVector sReturnValue;
269
270 for (size_t i = 0; i < vFileParts.size(); i++)
271 sReturnValue.push_back(vFileParts[i]);
272
273 return sReturnValue;
274}
275
276
286{
287 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
288 funcArgs.nArg1 = 0;
289
290 std::vector<std::string> vFileList = getFileList(funcArgs.sArg1.view().to_string(), *(funcArgs.opt), funcArgs.nArg1);
291 StringVector sFileList;
292
293 for (unsigned int i = 0; i < vFileList.size(); i++)
294 {
295 sFileList.push_back(vFileList[i]);
296 }
297
298 if (!sFileList.size())
300
301 return sFileList;
302}
303
304
314{
315 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
316 funcArgs.nArg1 = 0;
317
318 std::vector<std::string> vFolderList = getFolderList(funcArgs.sArg1.view().to_string(), *(funcArgs.opt), funcArgs.nArg1);
319 StringVector sFolderList;
320
321 for (unsigned int i = 0; i < vFolderList.size(); i++)
322 {
323 sFolderList.push_back(vFolderList[i]);
324 }
325
326 if (!sFolderList.size())
328
329 return sFolderList;
330}
331
332
342{
343 return toString((int)funcArgs.sArg1.view().length());
344}
345
346
356{
357 return toString((int)getMatchingParenthesis(funcArgs.sArg1.view()) + 1);
358}
359
360
370{
371 StringVector sCodes;
372 StringView sView = funcArgs.sArg1.view();
373
374 for (unsigned int i = 0; i < sView.length(); i++)
375 {
376 sCodes.push_back((int)sView[i]);
377 }
378
379 return sCodes;
380}
381
382
392{
393 StringVector sCodes;
394 StringView sView = funcArgs.sArg1.view();
395 static Umlauts _umlauts;
396
397 for (unsigned int i = 0; i < sView.length(); i++)
398 {
399 if (isblank(sView[i])
400 && _umlauts.lower.find(sView[i]) == std::string::npos
401 && _umlauts.upper.find(sView[i]) == std::string::npos)
402 sCodes.push_back(true);
403 else
404 sCodes.push_back(false);
405 }
406
407 return sCodes;
408}
409
410
420{
421 StringVector sCodes;
422 StringView sView = funcArgs.sArg1.view();
423 static Umlauts _umlauts;
424
425 for (unsigned int i = 0; i < sView.length(); i++)
426 {
427 if (isalnum(sView[i])
428 || _umlauts.lower.find(sView[i]) != std::string::npos
429 || _umlauts.upper.find(sView[i]) != std::string::npos)
430 sCodes.push_back(true);
431 else
432 sCodes.push_back(false);
433 }
434
435 return sCodes;
436}
437
438
448{
449 StringVector sCodes;
450 StringView sView = funcArgs.sArg1.view();
451 static Umlauts _umlauts;
452
453 for (unsigned int i = 0; i < sView.length(); i++)
454 {
455 if (isalpha(sView[i])
456 || _umlauts.lower.find(sView[i]) != std::string::npos
457 || _umlauts.upper.find(sView[i]) != std::string::npos)
458 sCodes.push_back(true);
459 else
460 sCodes.push_back(false);
461 }
462
463 // Handle empty strings
464 if (sCodes.empty())
465 sCodes.push_back(false);
466
467 return sCodes;
468}
469
470
480{
481 StringVector sCodes;
482 StringView sView = funcArgs.sArg1.view();
483 static Umlauts _umlauts;
484
485 for (unsigned int i = 0; i < sView.length(); i++)
486 {
487 if (iscntrl(sView[i])
488 && _umlauts.lower.find(sView[i]) == std::string::npos
489 && _umlauts.upper.find(sView[i]) == std::string::npos)
490 sCodes.push_back(true);
491 else
492 sCodes.push_back(false);
493 }
494
495 // Handle empty strings
496 if (sCodes.empty())
497 sCodes.push_back(false);
498
499 return sCodes;
500}
501
502
512{
513 StringVector sCodes;
514 StringView sView = funcArgs.sArg1.view();
515
516 for (unsigned int i = 0; i < sView.length(); i++)
517 {
518 if (isdigit(sView[i]))
519 sCodes.push_back(true);
520 else
521 sCodes.push_back(false);
522 }
523
524 // Handle empty strings
525 if (sCodes.empty())
526 sCodes.push_back(false);
527
528 return sCodes;
529}
530
531
541{
542 StringView sView = funcArgs.sArg1.view();
543
544 if (is_dir(sView.to_string()))
545 return true;
546
547 return false;
548}
549
550
560{
561 StringView sView = funcArgs.sArg1.view();
562
563 if (is_file(sView.to_string()))
564 return true;
565
566 return false;
567}
568
569
579{
580 StringVector sCodes;
581 StringView sView = funcArgs.sArg1.view();
582 static Umlauts _umlauts;
583
584 for (unsigned int i = 0; i < sView.length(); i++)
585 {
586 if (isgraph(sView[i])
587 || _umlauts.lower.find(sView[i]) != std::string::npos
588 || _umlauts.upper.find(sView[i]) != std::string::npos)
589 sCodes.push_back(true);
590 else
591 sCodes.push_back(false);
592 }
593
594 return sCodes;
595}
596
597
607{
608 StringVector sCodes;
609 StringView sView = funcArgs.sArg1.view();
610 // Get an Umlauts structure instance and store it statically
611 // (this variable will only be instantiated once and kept in
612 // memory afterwards, which is more efficient)
613 static Umlauts _umlauts;
614
615 for (unsigned int i = 0; i < sView.length(); i++)
616 {
617 // If the current character is found by "islower()" or is
618 // part of the "lower" field of the "Umlauts" structure,
619 // then it is a lowercase letter. In all other cases, it
620 // is not
621 if (islower(sView[i])
622 || _umlauts.lower.find(sView[i]) != std::string::npos)
623 sCodes.push_back(true);
624 else
625 sCodes.push_back(false);
626 }
627
628 // Handle empty strings
629 if (sCodes.empty())
630 sCodes.push_back(false);
631
632 return sCodes;
633}
634
635
645{
646 StringVector sCodes;
647 StringView sView = funcArgs.sArg1.view();
648 static Umlauts _umlauts;
649
650 for (unsigned int i = 0; i < sView.length(); i++)
651 {
652 if (isprint(sView[i])
653 || _umlauts.lower.find(sView[i]) != std::string::npos
654 || _umlauts.upper.find(sView[i]) != std::string::npos)
655 sCodes.push_back(true);
656 else
657 sCodes.push_back(false);
658 }
659
660 // Handle empty strings
661 if (sCodes.empty())
662 sCodes.push_back(false);
663
664 return sCodes;
665}
666
667
677{
678 StringVector sCodes;
679 StringView sView = funcArgs.sArg1.view();
680
681 static Umlauts _umlauts;
682
683 for (unsigned int i = 0; i < sView.length(); i++)
684 {
685 if (ispunct(sView[i])
686 && _umlauts.lower.find(sView[i]) == std::string::npos
687 && _umlauts.upper.find(sView[i]) == std::string::npos)
688 sCodes.push_back(true);
689 else
690 sCodes.push_back(false);
691 }
692
693 // Handle empty strings
694 if (sCodes.empty())
695 sCodes.push_back(false);
696
697 return sCodes;
698}
699
700
710{
711 StringVector sCodes;
712 StringView sView = funcArgs.sArg1.view();
713
714 static Umlauts _umlauts;
715
716 for (unsigned int i = 0; i < sView.length(); i++)
717 {
718 if (isspace(sView[i])
719 && _umlauts.lower.find(sView[i]) == std::string::npos
720 && _umlauts.upper.find(sView[i]) == std::string::npos)
721 sCodes.push_back(true);
722 else
723 sCodes.push_back(false);
724 }
725
726 // Handle empty strings
727 if (sCodes.empty())
728 sCodes.push_back(false);
729
730 return sCodes;
731}
732
733
743{
744 StringVector sCodes;
745 StringView sView = funcArgs.sArg1.view();
746
747 static Umlauts _umlauts;
748
749 for (unsigned int i = 0; i < sView.length(); i++)
750 {
751 if (isupper(sView[i])
752 || _umlauts.upper.find(sView[i]) != std::string::npos)
753 sCodes.push_back(true);
754 else
755 sCodes.push_back(false);
756 }
757
758 // Handle empty strings
759 if (sCodes.empty())
760 sCodes.push_back(false);
761
762 return sCodes;
763}
764
765
775{
776 StringVector sCodes;
777 StringView sView = funcArgs.sArg1.view();
778
779 for (unsigned int i = 0; i < sView.length(); i++)
780 {
781 if (isxdigit(sView[i]))
782 sCodes.push_back(true);
783 else
784 sCodes.push_back(false);
785 }
786
787 // Handle empty strings
788 if (sCodes.empty())
789 sCodes.push_back(false);
790
791 return sCodes;
792}
793
794
804{
805 std::string sToChar = "";
806
807 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
808 {
809 sToChar += (char)(funcArgs.nMultiArg[i]);
810 }
811
812 return "\"" + sToChar + "\"";
813}
814
815
825{
826 if (!funcArgs.nMultiArg.size())
827 return false;
828
829 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
830 {
831 if (!funcArgs.nMultiArg[i])
832 return false;
833 }
834
835 return true;
836}
837
838
848{
849 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
850 {
851 if (funcArgs.nMultiArg[i])
852 return true;
853 }
854
855 return false;
856}
857
858
868{
869 bool isTrue = false;
870
871 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
872 {
873 if (funcArgs.nMultiArg[i])
874 {
875 if (!isTrue)
876 isTrue = true;
877 else
878 return false;
879 }
880 }
881
882 return isTrue;
883}
884
885
895{
896 StringView sView1 = funcArgs.sArg1.view();
897 StringView sView2 = funcArgs.sArg2.view();
898 FileSystem _fSys;
899 _fSys.setTokens(funcArgs.opt->getTokenPaths());
900
901 if (sView2.length())
902 _fSys.setPath(sView2.to_string(), false, funcArgs.opt->getExePath());
903 else
904 _fSys.setPath(funcArgs.opt->getExePath(), false, funcArgs.opt->getExePath());
905
906 StringView sExtension = std::string(".dat");
907
908 if (sView1.rfind('.') != std::string::npos)
909 {
910 sExtension = sView1.subview(sView1.rfind('.'));
911
912 if (sExtension.find('*') != std::string::npos || sExtension.find('?') != std::string::npos)
913 sExtension = std::string(".dat");
914 else
915 _fSys.declareFileType(sExtension.to_string());
916 }
917
918 std::string sFile = _fSys.ValidFileName(sView1.to_string(), sExtension.to_string());
919
920 if (fileExists(sFile))
921 return true;
922
923 return false;
924}
925
926
936{
937 StringVector sSplittedString;
938 std::string sSep = funcArgs.sArg2.view().to_string();
939
940 if (!sSep.length())
942
943 boost::char_separator<char> cSep(sSep.c_str());
944
945 std::string sToSeparate = funcArgs.sArg1.view().to_string();
946 boost::tokenizer<boost::char_separator<char> > tok(sToSeparate, cSep);
947
948 for (boost::tokenizer<boost::char_separator<char> >::iterator iter = tok.begin(); iter != tok.end(); ++iter)
949 {
950 sSplittedString.push_back(std::string(*iter));
951 }
952
953 return sSplittedString;
954}
955
956
966{
967 std::string sTime = funcArgs.sArg2.view().to_string() + " ";
968
969 if (!funcArgs.sArg1.view().length() && isConvertible(sTime, CONVTYPE_DATE_TIME))
970 return toCmdString(to_double(StrToTime(sTime)));
971
972 std::string sPattern = funcArgs.sArg1.view().to_string() + " ";
973
974 if (sTime.length() != sPattern.length())
975 return "nan";
976
979 timeStruct.m_hours = std::chrono::hours::zero();
980 timeStruct.m_minutes = std::chrono::minutes::zero();
981 timeStruct.m_seconds = std::chrono::seconds::zero();
982 timeStruct.m_millisecs = std::chrono::milliseconds::zero();
983 timeStruct.m_microsecs = std::chrono::microseconds::zero();
984
985 char cCurrentChar = sPattern.front();
986 std::string sCurrentElement;
987 date::year y{1970u};// timeStruct.m_ymd.year();
988
989 if (sPattern.find_first_of("MD") != std::string::npos)
990 y = timeStruct.m_ymd.year();
991
992 date::month m{1u};// timeStruct.m_ymd.month();
993 date::day d{1u};//timeStruct.m_ymd.day();
994
995 for (size_t i = 0; i < sPattern.length(); i++)
996 {
997 if (sPattern[i] != cCurrentChar)
998 {
999 switch (cCurrentChar)
1000 {
1001 case 'y':
1002 case 'Y': // year is either four or two chars long. The structure expects the time to start at the year 1900
1003 if (sCurrentElement.length() > 2)
1004 y = date::year(StrToInt(sCurrentElement));
1005 else
1006 y = date::year(StrToInt(sCurrentElement) + 2000);
1007 break;
1008 case 'M':
1009 m = date::month(StrToInt(sCurrentElement));
1010 break;
1011 case 'D':
1012 d = date::day(StrToInt(sCurrentElement));
1013 break;
1014 case 'H':
1015 timeStruct.m_hours = std::chrono::hours(StrToInt(sCurrentElement));
1016 break;
1017 case 'h':
1018 timeStruct.m_hours = std::chrono::hours(StrToInt(sCurrentElement) + (tz.Bias + tz.DayLightBias).count() / 60);
1019 break;
1020 case 'm':
1021 timeStruct.m_minutes = std::chrono::minutes(StrToInt(sCurrentElement));
1022 break;
1023 case 's':
1024 timeStruct.m_seconds = std::chrono::seconds(StrToInt(sCurrentElement));
1025 break;
1026 case 'i':
1027 sCurrentElement.append(3-sCurrentElement.size(), '0');
1028 timeStruct.m_millisecs = std::chrono::milliseconds(StrToInt(sCurrentElement));
1029 break;
1030 case 'u':
1031 sCurrentElement.append(3-sCurrentElement.size(), '0');
1032 timeStruct.m_microsecs = std::chrono::microseconds(StrToInt(sCurrentElement));
1033 break;
1034 }
1035
1036 cCurrentChar = sPattern[i];
1037 sCurrentElement.clear();
1038 }
1039
1040 sCurrentElement += sTime[i];
1041 }
1042
1043 timeStruct.m_ymd = date::year_month_day(y,m,d);
1044
1045 return toCmdString(to_double(getTimePointFromTimeStamp(timeStruct)));
1046}
1047
1048
1058{
1059 std::string sStr = funcArgs.sArg1.view().to_string();
1060 StringView sView = funcArgs.sArg2.view();
1061
1062 if (!sView.length())
1063 return "0";
1064
1065 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1066 funcArgs.nArg1 = 1;
1067
1068 return toString((int)sView.find(sStr, funcArgs.nArg1 - 1) + 1);
1069}
1070
1071
1081{
1082 std::string sStr = funcArgs.sArg1.view().to_string();
1083 StringView sView = funcArgs.sArg2.view();
1084
1085 if (!sView.length())
1086 return "0";
1087
1088 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1089 funcArgs.nArg1 = 1;
1090
1091 if (funcArgs.nArg2 == DEFAULT_NUM_ARG || funcArgs.nArg2 <= 0 || sView.length() < (size_t)funcArgs.nArg2)
1092 funcArgs.nArg2 = sView.length();
1093
1094 StringVector positions;
1095 size_t pos_start = funcArgs.nArg1 - 1;
1096 size_t pos_last = funcArgs.nArg2 - sStr.length();
1097
1098 while (pos_start <= pos_last)
1099 {
1100 pos_start = sView.find(sStr, pos_start);
1101
1102 if (pos_start <= pos_last)
1103 {
1104 pos_start++;
1105
1106 positions.push_back(pos_start);
1107 }
1108 else
1109 {
1110 if (positions.size())
1111 return positions;
1112
1113 return "0";
1114 }
1115 }
1116
1117 if (!positions.size())
1118 return "0";
1119
1120 return positions;
1121}
1122
1123
1133{
1134 StringView sStr = funcArgs.sArg1.view();
1135 StringView sView = funcArgs.sArg2.view();
1136
1137 if (!sView.length())
1138 return "0";
1139
1140 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1141 funcArgs.nArg1 = 1;
1142
1143 if (funcArgs.nArg2 == DEFAULT_NUM_ARG || funcArgs.nArg2 <= 0 || sView.length() < (size_t)funcArgs.nArg2)
1144 funcArgs.nArg2 = sView.length();
1145
1146 StringVector positions;
1147 size_t pos_start = funcArgs.nArg1 - 1;
1148 size_t pos_last = funcArgs.nArg2 - 1;
1149
1150 for (size_t i = 0; i < sStr.length(); i++)
1151 {
1152 size_t match = sView.find(sStr[i], pos_start);
1153
1154 if (match <= pos_last)
1155 positions.push_back(match+1);
1156 else
1157 positions.push_back(0);
1158 }
1159
1160 if (!positions.size())
1161 return "0";
1162
1163 return positions;
1164}
1165
1166
1176{
1177 std::string sStr = funcArgs.sArg1.view().to_string();
1178 StringView sView = funcArgs.sArg2.view();
1179
1180 if (!sView.length())
1181 return "0";
1182
1183 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1184 funcArgs.nArg1 = 1;
1185
1186 return toString((int)sView.find_first_of(sStr, funcArgs.nArg1 - 1) + 1);
1187}
1188
1189
1199{
1200 std::string sStr = funcArgs.sArg1.view().to_string();
1201 StringView sView = funcArgs.sArg2.view();
1202
1203 if (!sView.length())
1204 return "0";
1205
1206 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1207 funcArgs.nArg1 = 1;
1208
1209 return toString((int)sView.find_first_not_of(sStr, funcArgs.nArg1 - 1) + 1);
1210}
1211
1212
1222{
1223 std::string sStr = funcArgs.sArg1.view().to_string();
1224 StringView sView = funcArgs.sArg2.view();
1225
1226 if (!sView.length())
1227 return "0";
1228
1229 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1230 funcArgs.nArg1 = sView.length() + 1;
1231
1232 return toString((int)sView.rfind(sStr, funcArgs.nArg1 - 1) + 1);
1233}
1234
1235
1245{
1246 std::string sStr = funcArgs.sArg1.view().to_string();
1247 StringView sView = funcArgs.sArg2.view();
1248
1249 if (!sView.length())
1250 return "0";
1251
1252 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1253 funcArgs.nArg1 = sView.length() + 1;
1254
1255 return toString((int)sView.find_last_of(sStr, funcArgs.nArg1 - 1) + 1);
1256}
1257
1258
1268{
1269 std::string sStr = funcArgs.sArg1.view().to_string();
1270 StringView sView = funcArgs.sArg2.view();
1271
1272 if (!sView.length())
1273 return "0";
1274
1275 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 <= 0 || sView.length() < (size_t)funcArgs.nArg1)
1276 funcArgs.nArg1 = sView.length() + 1;
1277
1278 return toString((int)sView.find_last_not_of(sStr, funcArgs.nArg1 - 1) + 1);
1279}
1280
1281
1291{
1292 StringView sView1 = funcArgs.sArg1.view();
1293 StringView sView2 = funcArgs.sArg2.view();
1294 StringView sView3 = funcArgs.sArg3.view();
1295
1296 if (!sView2.length())
1297 return "0";
1298
1299 size_t nMatch;
1300
1301 if (sView3.length())
1302 nMatch = findParameter(sView2.to_string(), sView1.to_string(), sView3[0]);
1303 else
1304 nMatch = findParameter(sView2.to_string(), sView1.to_string());
1305
1306 if (nMatch)
1307 return toString((int)nMatch); // findParameter returns already pos+1
1308 else
1309 return "0";
1310}
1311
1312
1322{
1323 StringView sView = funcArgs.sArg1.view();
1324
1325 if (!sView.length())
1327
1328 if (funcArgs.nArg1 < 1)
1329 funcArgs.nArg1 = 1;
1330
1331 if ((size_t)funcArgs.nArg1 > sView.length())
1333
1334 if (funcArgs.nArg2 < 0)
1335 funcArgs.nArg2 = -1;
1336
1337 return "\"" + sView.subview(funcArgs.nArg1 - 1, funcArgs.nArg2).to_string() + "\"";
1338}
1339
1340
1350{
1351 std::string sReturn;
1352 std::string sStr = funcArgs.sArg1.view().to_string();
1353
1354 for (int i = 0; i < funcArgs.nArg1; i++)
1355 sReturn += sStr;
1356
1357 return "\"" + sReturn + "\"";
1358}
1359
1360
1369static std::string padWithZeros(int nTime, size_t nLength)
1370{
1371 std::string sPadded = toString(nTime);
1372 sPadded.insert(0, nLength - sPadded.length(), '0');
1373 return sPadded;
1374}
1375
1376
1386{
1387 if (!funcArgs.sArg1.view().length())
1388 return "\"" + toString(to_timePoint(funcArgs.dArg1.real()), 0) + "\"";
1389
1390 std::string sFormattedTime = funcArgs.sArg1.view().to_string() + " "; // contains pattern
1391 sys_time_point nTime = to_timePoint(funcArgs.dArg1.real());
1392 time_stamp timeStruct = getTimeStampFromTimePoint(nTime);
1394
1395 char cCurrentChar = sFormattedTime.front();
1396 size_t currentElementStart = 0;
1397
1398 for (size_t i = 0; i < sFormattedTime.length(); i++)
1399 {
1400 if (cCurrentChar != sFormattedTime[i])
1401 {
1402 switch (cCurrentChar)
1403 {
1404 case 'Y':
1405 case 'y':
1406 if (i - currentElementStart > 2)
1407 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(int(timeStruct.m_ymd.year()), i - currentElementStart));
1408 else
1409 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(int(timeStruct.m_ymd.year()) - 100 * (int(timeStruct.m_ymd.year()) / 100), i - currentElementStart));
1410 break;
1411 case 'M':
1412 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(unsigned(timeStruct.m_ymd.month()), i - currentElementStart));
1413 break;
1414 case 'D':
1415 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(unsigned(timeStruct.m_ymd.day()), i - currentElementStart));
1416 break;
1417 case 'd':
1418 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros((date::sys_days(timeStruct.m_ymd) - date::sys_days(timeStruct.m_ymd.year()/1u/1u)).count()+1, i - currentElementStart));
1419 break;
1420 case 'H':
1421 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_hours.count(), i - currentElementStart));
1422 break;
1423 case 'h':
1424 if (timeStruct.m_hours.count() - (tz.Bias + tz.DayLightBias).count() / 60 < 0)
1425 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_hours.count() + 24 - (tz.Bias + tz.DayLightBias).count() / 60, i - currentElementStart));
1426 else if (timeStruct.m_hours.count() - (tz.Bias + tz.DayLightBias).count() / 60 >= 24)
1427 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_hours.count() - 24 - (tz.Bias + tz.DayLightBias).count() / 60, i - currentElementStart));
1428 else
1429 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_hours.count() - (tz.Bias + tz.DayLightBias).count() / 60, i - currentElementStart));
1430 break;
1431 case 'm':
1432 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_minutes.count(), i - currentElementStart));
1433 break;
1434 case 's':
1435 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_seconds.count(), i - currentElementStart));
1436 break;
1437 case 'i':
1438 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_millisecs.count(), i - currentElementStart));
1439 break;
1440 case 'u':
1441 sFormattedTime.replace(currentElementStart, i - currentElementStart, padWithZeros(timeStruct.m_microsecs.count(), i - currentElementStart));
1442 break;
1443 }
1444
1445 currentElementStart = i;
1446 cCurrentChar = sFormattedTime[i];
1447 }
1448 }
1449 sFormattedTime.pop_back();
1450 return "\"" + sFormattedTime + "\"";
1451}
1452
1453
1463{
1464 sys_time_point nTime = to_timePoint(funcArgs.dArg1.real());
1465
1466 size_t day = getWeekDay(nTime);
1467
1468 if (funcArgs.nArg1 == DEFAULT_NUM_ARG || funcArgs.nArg1 == 0)
1469 return to_string(day);
1470
1471 std::vector<std::string> weekdays = _lang.getList("COMMON_WEEKDAY_*");
1472
1473 if (weekdays.size() >= 7)
1474 return "\"" + weekdays[day-1] + "\"";
1475
1476 return "\"UNDEFINED\"";
1477}
1478
1479
1489{
1490 std::string sStr = funcArgs.sArg1.view().to_string();
1491
1492 if (funcArgs.nArg1 <= 1)
1493 return "\"" + sStr.substr(0, 1) + "\"";
1494
1495 if ((size_t)funcArgs.nArg1 >= sStr.length())
1496 return "\"" + sStr.substr(sStr.length() - 1) + "\"";
1497
1498 return "\"" + sStr.substr(funcArgs.nArg1 - 1, 1) + "\"";
1499}
1500
1501
1511{
1512 std::string sStr = funcArgs.sArg1.view().to_string();
1513
1514 if (funcArgs.nArg1 <= 1)
1515 funcArgs.nArg1 = 1;
1516
1517 if ((size_t)funcArgs.nArg1 > sStr.length())
1519
1520 return "\"" + getArgAtPos(sStr, funcArgs.nArg1 - 1) + "\"";
1521}
1522
1523
1533{
1534 StringView sView1 = funcArgs.sArg1.view();
1535 StringView sView2 = funcArgs.sArg2.view();
1536
1537 if (!sView1.length())
1539
1540 if (funcArgs.nArg1 < 1)
1541 funcArgs.nArg1 = 1;
1542
1543 if ((size_t)funcArgs.nArg1 > sView1.length())
1544 funcArgs.nArg1 = sView1.length();
1545
1546 if (funcArgs.nArg2 == DEFAULT_NUM_ARG)
1547 funcArgs.nArg2 = -1;
1548
1549 return "\"" + sView1.to_string().replace(funcArgs.nArg1 - 1, funcArgs.nArg2, sView2.to_string()) + "\"";
1550}
1551
1552
1554{
1558 HEX
1560
1561
1571static long long int convertBaseToDecimal(StringView value, NumberBase base)
1572{
1573 std::stringstream stream;
1574 long long int ret = 0;
1575
1576 if (base == HEX)
1577 stream.setf(std::ios::hex, std::ios::basefield);
1578 else if (base == OCT)
1579 stream.setf(std::ios::oct, std::ios::basefield);
1580 else if (base == BIN)
1581 {
1582 for (int i = value.length() - 1; i >= 0; i--)
1583 {
1584 if (value[i] == '1')
1585 ret += intPower(2, value.length()-1 - i);
1586 }
1587
1588 return ret;
1589 }
1590 else if (base == LOG)
1591 {
1592 if (toLowerCase(value.to_string()) == "true" || value == "1")
1593 return 1LL;
1594
1595 return 0LL;
1596 }
1597
1598 stream << value.to_string();
1599 stream >> ret;
1600
1601 return ret;
1602}
1603
1604
1613static double extractLaTeXExponent(std::string& sExpr)
1614{
1615 double val;
1616
1617 if (sExpr.find('{') != std::string::npos)
1618 {
1619 // a^{xyz}
1620 val = std::stod(sExpr.substr(sExpr.find('{')+1, sExpr.find('}')));
1621 sExpr.erase(0, sExpr.find('}')+1);
1622 }
1623 else
1624 {
1625 // a^b
1626 val = std::stod(sExpr.substr(sExpr.find_first_not_of("^ "), 1));
1627 sExpr.erase(0, sExpr.find_first_not_of("^ ")+1);
1628 }
1629
1630 return val;
1631}
1632
1633
1643{
1644 StringView sView1 = funcArgs.sArg1.view();
1645 StringView sView2 = funcArgs.sArg2.view();
1646
1647 // Exclude border cases
1648 if (!sView1.length())
1650
1651 if (!sView2.length())
1652 return "\"" + sView1.to_string() + "\"";
1653
1654 // Ensure that the indices are valid
1655 if (funcArgs.nArg1 < 1)
1656 funcArgs.nArg1 = 1;
1657
1658 if ((size_t)funcArgs.nArg1 > sView1.length())
1660
1661 if (funcArgs.nArg2 == DEFAULT_NUM_ARG)
1662 funcArgs.nArg2 = -1;
1663
1664 // Examples for text, which shall be parsed
1665 // 2018-09-21: Message VAL=12452
1666 // %s: %s VAL=%f
1667 // {sDate, sMessage, fValue} = textparse("2018-09-21: Message VAL=12452", "%s: %s VAL=%f");
1668
1669 StringVector sParsedStrings;
1670 size_t lastPosition = funcArgs.nArg1 - 1;
1671 static std::string sIDENTIFIERCHARS = "sfaLlthbo";
1672
1673 // If the search string starts with whitespaces and the
1674 // pattern doesn't start with a percentage sign, search
1675 // for the first non-whitespace character
1676 if (sView2.front() != '%' && sView1.front() == ' ')
1677 {
1678 lastPosition = sView1.find_first_not_of(' ');
1679 }
1680
1681 // Go through the pattern
1682 for (size_t i = 0; i < sView2.length(); i++)
1683 {
1684 // Ensure that the last position is considered
1685 if (lastPosition > (size_t)funcArgs.nArg2)
1686 break;
1687
1688 // Find the identifiers
1689 if (i+1 < sView2.length() && sView2[i] == '%' && sIDENTIFIERCHARS.find(sView2[i+1]) != std::string::npos)
1690 {
1691 // Find the following identifier
1692 size_t pos = std::string::npos;
1693
1694 for (size_t j = i+2; j < sView2.length(); j++)
1695 {
1696 if (j+1 < sView2.length() && sView2[j] == '%' && sIDENTIFIERCHARS.find(sView2[j+1]) != std::string::npos)
1697 {
1698 pos = j;
1699 break;
1700 }
1701 }
1702
1703 // Define the search pattern to find the
1704 // separator at the end of the current
1705 // token
1706 std::string sSearchPattern = sView2.subview(i+2, pos - i - 2).to_string();
1707
1708 if (!sSearchPattern.length())
1709 pos = std::string::npos;
1710 else
1711 pos = sView1.find(sSearchPattern, lastPosition);
1712
1713 // Ensure that the found position is inside
1714 // the right border
1715 if (pos > (size_t)funcArgs.nArg2 && (size_t)funcArgs.nArg2 < sView1.length())
1716 break;
1717
1718 // Append the found token
1719 if (sView2.subview(i, 2) == "%s")
1720 sParsedStrings.push_back(sView1.subview(lastPosition, pos - lastPosition).to_string());
1721 else if (sView2.subview(i, 2) == "%h")
1722 sParsedStrings.push_back(convertBaseToDecimal(sView1.subview(lastPosition, pos - lastPosition), HEX));
1723 else if (sView2.subview(i, 2) == "%o")
1724 sParsedStrings.push_back(convertBaseToDecimal(sView1.subview(lastPosition, pos - lastPosition), OCT));
1725 else if (sView2.subview(i, 2) == "%b")
1726 sParsedStrings.push_back(convertBaseToDecimal(sView1.subview(lastPosition, pos - lastPosition), BIN));
1727 else if (sView2.subview(i, 2) == "%l")
1728 sParsedStrings.push_back(convertBaseToDecimal(sView1.subview(lastPosition, pos - lastPosition), LOG));
1729 else if (sView2.subview(i, 2) == "%t")
1730 sParsedStrings.push_back(mu::value_type(to_double(StrToTime(sView1.subview(lastPosition, pos - lastPosition).to_string()))));
1731 else if (sView2.subview(i, 2) == "%f")
1732 {
1733 std::string sFloatingPoint = sView1.subview(lastPosition, pos - lastPosition).to_string();
1734
1735 if (sFloatingPoint.find('.') == std::string::npos)
1736 replaceAll(sFloatingPoint, ",", ".");
1737
1738 sParsedStrings.push_back(isConvertible(sFloatingPoint, CONVTYPE_VALUE) ? StrToCmplx(sFloatingPoint) : NAN);
1739 }
1740 else if (sView2.subview(i, 2) == "%L")
1741 {
1742 std::string sLaTeXFormatted = sView1.subview(lastPosition, pos - lastPosition).to_string();
1743 StripSpaces(sLaTeXFormatted);
1744
1745 if (sLaTeXFormatted.front() == '$' && sLaTeXFormatted.back() == '$')
1746 {
1747 sLaTeXFormatted = sLaTeXFormatted.substr(1, sLaTeXFormatted.length()-2);
1748 StripSpaces(sLaTeXFormatted);
1749 }
1750
1751 replaceAll(sLaTeXFormatted, "{,}", ".");
1752 replaceAll(sLaTeXFormatted, "\\times", "*");
1753 replaceAll(sLaTeXFormatted, "\\cdot", "*");
1754 replaceAll(sLaTeXFormatted, "2\\pi", "6.283185");
1755 replaceAll(sLaTeXFormatted, "\\pi", "3.1415926");
1756 replaceAll(sLaTeXFormatted, "\\infty", "inf");
1757 replaceAll(sLaTeXFormatted, "---", "nan");
1758 replaceAll(sLaTeXFormatted, "\\,", " ");
1759 // 1.0*10^{-5} 1.0*10^2 1.0*10^3 2.5^{0.5}
1760
1761 if (sLaTeXFormatted.find('^') != std::string::npos)
1762 {
1763 mu::value_type vVal = 0;
1764 mu::value_type vValFinal = 0;
1765
1766 size_t nOpPos = std::string::npos;
1767
1768 // Go through all exponents and parse them into complex double format
1769 while (sLaTeXFormatted.length())
1770 {
1771 nOpPos = sLaTeXFormatted.find_first_of("*^");
1772 vVal = StrToCmplx(sLaTeXFormatted.substr(0, nOpPos));
1773
1774 if (sLaTeXFormatted[nOpPos] == '*')
1775 {
1776 sLaTeXFormatted.erase(0, nOpPos+1);
1777 nOpPos = sLaTeXFormatted.find('^');
1778 mu::value_type vBase = StrToCmplx(sLaTeXFormatted.substr(0, nOpPos));
1779 sLaTeXFormatted.erase(0, nOpPos+1);
1780 vVal *= std::pow(vBase, extractLaTeXExponent(sLaTeXFormatted));
1781 }
1782 else
1783 {
1784 sLaTeXFormatted.erase(0, nOpPos+1);
1785 vVal = std::pow(vVal, extractLaTeXExponent(sLaTeXFormatted));
1786 }
1787
1788 if (sLaTeXFormatted.find_first_not_of(" *") != std::string::npos
1789 && tolower(sLaTeXFormatted[sLaTeXFormatted.find_first_not_of(" *")]) == 'i')
1790 {
1791 vVal = mu::value_type(vVal.imag(), vVal.real());
1792 sLaTeXFormatted.erase(0, sLaTeXFormatted.find_first_of("iI")+1);
1793 }
1794
1795 vValFinal += vVal;
1796
1797 if (sLaTeXFormatted.find_first_not_of(' ') == std::string::npos)
1798 break;
1799 }
1800
1801
1802 sParsedStrings.push_back(vValFinal);
1803 }
1804 else // This can handle simple multiplications
1805 sParsedStrings.push_back(StrToCmplx(sLaTeXFormatted));
1806 }
1807
1808 // Store the position of the separator
1809 lastPosition = pos;
1810 i++;
1811 }
1812 else
1813 lastPosition++;
1814 }
1815
1816 return sParsedStrings;
1817}
1818
1819
1829{
1830 StringVector sIds;
1831
1832 // Remove the masked strings
1833 StringView sView = funcArgs.sArg2.view();
1834
1835 // Set the default tolerance mode, if necessary
1836 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
1837 funcArgs.nArg1 = 0;
1838
1839 // Examine the whole string array
1840 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
1841 {
1842 StringView arg = funcArgs.sMultiArg[i];
1843
1844 // Apply the chosen matching method
1845 if (funcArgs.nArg1 == 1)
1846 {
1847 // Remove surrounding whitespaces and compare
1848 arg.strip();
1849
1850 if (arg == sView)
1851 sIds.push_back(i+1);
1852 }
1853 else if (funcArgs.nArg1 == 2)
1854 {
1855 // Take the first non-whitespace characters
1856 if (arg.find_first_not_of(' ') != std::string::npos
1857 && arg.subview(arg.find_first_not_of(' '), sView.length()) == sView)
1858 sIds.push_back(i+1);
1859 }
1860 else if (funcArgs.nArg1 == 3)
1861 {
1862 // Take the last non-whitespace characters
1863 if (arg.find_last_not_of(' ') != std::string::npos
1864 && arg.find_last_not_of(' ')+1 >= sView.length()
1865 && arg.subview(arg.find_last_not_of(' ')-sView.length()+1, sView.length()) == sView)
1866 sIds.push_back(i+1);
1867 }
1868 else if (funcArgs.nArg1 == 4)
1869 {
1870 // Search anywhere in the string
1871 if (arg.find(sView.to_string()) != std::string::npos)
1872 sIds.push_back(i+1);
1873 }
1874 else if (funcArgs.nArg1 == 5)
1875 {
1876 // Search any of the characters in the string
1877 if (arg.find_first_of(sView.to_string()) != std::string::npos)
1878 sIds.push_back(i+1);
1879 }
1880 else
1881 {
1882 // Simply compare
1883 if (arg == sView)
1884 sIds.push_back(i+1);
1885 }
1886 }
1887
1888 // Pop the trailing comma, if the string has a length.
1889 // Otherwise set the ID to 0 - nothing found
1890 if (!sIds.size())
1891 return "0";
1892
1893 return sIds;
1894}
1895
1896
1906{
1907 // Set the default tolerance mode, if necessary
1908 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
1909 funcArgs.nArg1 = funcArgs.sMultiArg.size() > 1 ? 0 : 1;
1910
1911 StringVector sUniqueStrings;
1912
1913 // Separate unique strings from unique chars
1914 if (funcArgs.nArg1 == 0)
1915 {
1916 // Create a copy of all values (we do
1917 // not need to remove the quotation marks here)
1918 s_vect vFuncArgs = funcArgs.sMultiArg;
1919
1920 // Sort and isolate the unique values
1921 std::sort(vFuncArgs.begin(), vFuncArgs.end());
1922 auto iter = std::unique(vFuncArgs.begin(), vFuncArgs.end());
1923
1924 // Copy together
1925 for (auto it = vFuncArgs.begin(); it != iter; ++it)
1926 {
1927 sUniqueStrings.push_generic(*it); // Should already contain the surrounding quotation marks
1928 }
1929 }
1930 else
1931 {
1932 // Examine each value independently
1933 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
1934 {
1935 // Get a quotation mark free copy
1936 std::string sArg = funcArgs.sMultiArg[i].to_string();
1937
1938 // Sort and isolate the unique chars
1939 std::sort(sArg.begin(), sArg.end());
1940 auto iter = std::unique(sArg.begin(), sArg.end());
1941
1942 // Append the string with unique characters
1943 sUniqueStrings.push_back(std::string(sArg.begin(), iter));
1944 }
1945 }
1946
1947 return sUniqueStrings;
1948}
1949
1950
1960{
1961 StringVector sValues;
1962
1963 StringView sView2 = funcArgs.sArg2.view();
1964
1965 // Set the default tolerance mode, if necessary
1966 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
1967 funcArgs.nArg1 = 0;
1968
1969 // Ensure that the length of the array is
1970 // even
1971 if (funcArgs.sMultiArg.size() % 2)
1972 funcArgs.sMultiArg.pop_back();
1973
1974 // Examine the whole string array
1975 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i+=2)
1976 {
1977 // Remove the masked strings
1978 StringView arg = funcArgs.sMultiArg[i];
1979
1980 // Remove surrounding whitespaces and compare
1981 arg.strip();
1982
1983 if (arg == sView2)
1984 sValues.push_generic(funcArgs.sMultiArg.getRef(i+1));
1985 }
1986
1987 // set values to the default values and probably
1988 // issue a warning, if no values were found
1989 if (!sValues.size())
1990 {
1991 if (funcArgs.nArg1)
1992 NumeReKernel::issueWarning(_lang.get("PARSERFUNCS_LISTFUNC_GETKEYVAL_WARNING", "\"" + sView2.to_string() + "\""));
1993
1994 sValues.push_generic(funcArgs.sArg3.getRef());
1995 }
1996
1997 return sValues;
1998}
1999
2000
2010{
2011 StringView sView1 = funcArgs.sArg1.view();
2012 std::string sStr2 = funcArgs.sArg2.view().to_string();
2013 std::string sStr3 = funcArgs.sArg3.view().to_string();
2014
2015 // Define default arguments
2016 if (!sStr3.length())
2017 sStr3 = " \t";
2018
2019 size_t nMatch = 0;
2020
2021 // search the first match of the token, which is surrounded by the
2022 // defined separator characters
2023 while ((nMatch = sView1.find(sStr2, nMatch)) != std::string::npos)
2024 {
2025 if ((!nMatch || sStr3.find(sView1[nMatch-1]) != std::string::npos)
2026 && (nMatch + sStr2.length() >= sView1.length() || sStr3.find(sView1[nMatch+sStr2.length()]) != std::string::npos))
2027 {
2028 return toString(nMatch + 1);
2029 }
2030
2031 nMatch++;
2032 }
2033
2034 return "0";
2035}
2036
2037
2047{
2048 std::string sStr1 = funcArgs.sArg1.view().to_string();
2049 std::string sStr2 = funcArgs.sArg2.view().to_string();
2050 std::string sStr3 = funcArgs.sArg3.view().to_string();
2051
2052 if (!sStr1.length())
2054
2055 if (funcArgs.nArg1 < 1)
2056 funcArgs.nArg1 = 1;
2057
2058 if ((size_t)funcArgs.nArg1 > sStr1.length())
2059 funcArgs.nArg1 = sStr1.length();
2060
2061 if (funcArgs.nArg2 == DEFAULT_NUM_ARG)
2062 funcArgs.nArg2 = sStr1.length() + 1;
2063
2064 if (!sStr2.length())
2065 return "\"" + sStr1 + "\"";
2066
2067 // Using the slower version to enable replacement of null characters
2068 replaceAll(sStr1, sStr2, sStr3, funcArgs.nArg1-1, funcArgs.nArg2-1);
2069
2070 return "\"" + sStr1 + "\"";
2071}
2072
2073
2083{
2084 StringView sView1 = funcArgs.sArg1.view();
2085 StringView sView2 = funcArgs.sArg2.view();
2086 StringView sView3 = funcArgs.sArg3.view();
2087
2088 if (!sView1.length())
2090
2091 while (sView2.length()
2092 && sView1.length() >= sView2.length()
2093 && sView1.subview(0, sView2.length()) == sView2)
2094 {
2095 sView1.trim_front(sView2.length());
2096
2097 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
2098 break;
2099 }
2100
2101 while (sView3.length()
2102 && sView1.length() >= sView3.length()
2103 && sView1.subview(sView1.length() - sView3.length()) == sView3)
2104 {
2105 sView1.trim_back(sView3.length());
2106
2107 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
2108 break;
2109 }
2110
2111 return "\"" + sView1.to_string() + "\"";
2112
2113}
2114
2115
2125{
2126 StringView sView1 = funcArgs.sArg1.view();
2127 StringView sView2 = funcArgs.sArg2.view();
2128
2129 if (!sView1.length())
2130 return StringVector(2, "0");
2131
2132 // Ensure that the indices are valid
2133 if (funcArgs.nArg1 < 1)
2134 funcArgs.nArg1 = 1;
2135
2136 if ((size_t)funcArgs.nArg1 > sView2.length())
2137 return StringVector(2, "0");
2138
2139 if (funcArgs.nArg2 == DEFAULT_NUM_ARG)
2140 funcArgs.nArg2 = -1;
2141
2142 try
2143 {
2144 std::smatch match;
2145 std::regex expr(sView1.to_string());
2146 std::string sStr = sView2.subview(funcArgs.nArg1-1, funcArgs.nArg2).to_string();
2147
2148 if (std::regex_search(sStr, match, expr))
2149 {
2150 StringVector sRet;
2151 sRet.push_back(match.position(0) + (size_t)funcArgs.nArg1);
2152 sRet.push_back(match.length(0));
2153 return sRet;
2154 }
2155 }
2156 catch (std::regex_error& e)
2157 {
2158 std::string message;
2159
2160 switch (e.code())
2161 {
2162 case std::regex_constants::error_collate:
2163 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_COLLATE");
2164 break;
2165 case std::regex_constants::error_ctype:
2166 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_CTYPE");
2167 break;
2168 case std::regex_constants::error_escape:
2169 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_ESCAPE");
2170 break;
2171 case std::regex_constants::error_backref:
2172 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_BACKREF");
2173 break;
2174 case std::regex_constants::error_brack:
2175 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_BRACK");
2176 break;
2177 case std::regex_constants::error_paren:
2178 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_PAREN");
2179 break;
2180 case std::regex_constants::error_brace:
2181 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_BRACE");
2182 break;
2183 case std::regex_constants::error_badbrace:
2184 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_BADBRACE");
2185 break;
2186 case std::regex_constants::error_range:
2187 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_RANGE");
2188 break;
2189 case std::regex_constants::error_space:
2190 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_SPACE");
2191 break;
2192 case std::regex_constants::error_badrepeat:
2193 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_BADREPEAT");
2194 break;
2195 case std::regex_constants::error_complexity:
2196 message =_lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_COMPLEXITY");
2197 break;
2198 case std::regex_constants::error_stack:
2199 message = _lang.get("ERR_NR_"+toString(SyntaxError::INVALID_REGEX)+"_STACK");
2200 break;
2201 }
2202
2204
2205 }
2206
2207 return StringVector(2, "0");
2208}
2209
2210
2220{
2221 if (funcArgs.sMultiArg.size())
2222 return toString((int)funcArgs.sMultiArg.size());
2223 else if (funcArgs.nMultiArg.size())
2224 return toString((int)funcArgs.nMultiArg.size());
2225
2226 return "0";
2227}
2228
2229
2239{
2240 if (funcArgs.sMultiArg.size())
2241 {
2242 int nRet = 0;
2243
2244 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
2245 {
2246 if (funcArgs.sMultiArg[i].length())
2247 nRet++;
2248 }
2249
2250 return toString(nRet);
2251 }
2252 else if (funcArgs.nMultiArg.size())
2253 return toString((int)funcArgs.nMultiArg.size());
2254
2255 return "0";
2256}
2257
2258
2268{
2269 StringVector logtoidx;
2270
2271 if (funcArgs.sMultiArg.size())
2272 {
2273 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
2274 {
2275 if (funcArgs.sMultiArg.is_string(i) && funcArgs.sMultiArg[i].length())
2276 logtoidx.push_back(i+1);
2277 else if (!funcArgs.sMultiArg.is_string(i) && funcArgs.sMultiArg[i] != "false" && funcArgs.sMultiArg[i] != "0")
2278 logtoidx.push_back(i+1);
2279 }
2280 }
2281 else if (funcArgs.nMultiArg.size())
2282 {
2283 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
2284 {
2285 if (funcArgs.nMultiArg[i])
2286 logtoidx.push_back(i+1);
2287 }
2288 }
2289
2290 if (logtoidx.size())
2291 return logtoidx;
2292
2293 return "0";
2294}
2295
2296
2306{
2307 StringVector idxtolog;
2308
2309 if (funcArgs.nMultiArg.size())
2310 {
2311 auto iter = std::max_element(funcArgs.nMultiArg.begin(), funcArgs.nMultiArg.end());
2312 idxtolog.resize(*iter, "false");
2313
2314 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
2315 {
2316 if (funcArgs.nMultiArg[i] > 0)
2317 idxtolog.getRef(funcArgs.nMultiArg[i]-1) = "true";
2318 }
2319 }
2320
2321 if (idxtolog.size())
2322 return idxtolog;
2323
2324 return "0";
2325}
2326
2327
2337{
2338 if (!funcArgs.sMultiArg.size())
2340
2341 StringView sMin = funcArgs.sMultiArg[0];
2342
2343 for (size_t i = 1; i < funcArgs.sMultiArg.size(); i++)
2344 {
2345 if (sMin > funcArgs.sMultiArg[i])
2346 sMin = funcArgs.sMultiArg[i];
2347 }
2348
2349 return "\"" + sMin.to_string() + "\"";
2350}
2351
2352
2362{
2363 if (!funcArgs.sMultiArg.size())
2365
2366 StringView sMax = funcArgs.sMultiArg[0];
2367
2368 for (size_t i = 1; i < funcArgs.sMultiArg.size(); i++)
2369 {
2370 if (sMax < funcArgs.sMultiArg[i])
2371 sMax = funcArgs.sMultiArg[i];
2372 }
2373
2374 return "\"" + sMax.to_string() + "\"";
2375}
2376
2377
2387{
2388 if (funcArgs.sMultiArg.size())
2389 {
2390 std::string sRet = "";
2391
2392 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
2393 sRet += funcArgs.sMultiArg[i].to_string();
2394
2395 return "\"" + sRet + "\"";
2396 }
2397 else if (funcArgs.nMultiArg.size())
2398 {
2399 int nRet = 0;
2400
2401 for (size_t i = 0; i < funcArgs.nMultiArg.size(); i++)
2402 nRet += funcArgs.nMultiArg[i];
2403
2404 return toString(nRet);
2405 }
2406
2408}
2409
2410
2420{
2421 StringView sView1 = funcArgs.sArg1.view();
2422 std::stringstream stream;
2423
2424 if (sView1 == "hex")
2425 stream.setf(std::ios::hex, std::ios::basefield);
2426 else if (sView1 == "oct")
2427 stream.setf(std::ios::oct, std::ios::basefield);
2428 else if (sView1 == "bin")
2429 {
2430 int i = 0;
2431 std::string ret;
2432
2433 while ((1 << i) <= funcArgs.nArg1)
2434 {
2435 if (funcArgs.nArg1 & (1 << i))
2436 ret.insert(0, "1");
2437 else
2438 ret.insert(0, "0");
2439
2440 i++;
2441 }
2442
2443 if (!ret.length())
2444 ret = "0";
2445
2446 return "\"" + ret + "\"";
2447 }
2448
2449 stream.setf(std::ios::showbase);
2450 stream << funcArgs.nArg1;
2451 std::string ret;
2452 stream >> ret;
2453
2454 return "\"" + ret + "\"";
2455}
2456
2457
2467{
2468 StringView sView1 = funcArgs.sArg1.view();
2469 StringView sView2 = funcArgs.sArg2.view();
2470 std::stringstream stream;
2471
2472 if (sView1 == "hex")
2473 return toString(convertBaseToDecimal(sView2, HEX));
2474 else if (sView1 == "oct")
2475 return toString(convertBaseToDecimal(sView2, OCT));
2476 else if (sView1 == "bin")
2477 return toString(convertBaseToDecimal(sView2, BIN));
2478
2479 return sView2.to_string();
2480}
2481
2482
2494{
2495 StringVector result;
2496
2497 // Set the default justification mode
2498 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
2499 funcArgs.nArg1 = -1;
2500
2501 // Find the string of max length
2502 size_t maxLength = 0;
2503
2504 // Examine the whole string array
2505 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
2506 {
2507 // Remove the masked strings
2508 StringView sStr = funcArgs.sMultiArg[i];
2509
2510 // Remove surrounding whitespaces
2511 sStr.strip();
2512
2513 if (sStr.length() > maxLength)
2514 maxLength = sStr.length();
2515 }
2516
2517 // Fill all string with as many whitespaces as necessary
2518 for (size_t i = 0; i < funcArgs.sMultiArg.size(); i++)
2519 {
2520 StringView view = funcArgs.sMultiArg[i];
2521 view.strip();
2522
2523 std::string sStr = view.to_string();
2524
2525 if (funcArgs.nArg1 == 1)
2526 sStr.insert(0, maxLength - sStr.size(), ' ');
2527 else if (funcArgs.nArg1 == -1)
2528 sStr.append(maxLength - sStr.size(), ' ');
2529 else if (funcArgs.nArg1 == 0)
2530 {
2531 size_t leftSpace = (maxLength - sStr.size()) / 2;
2532 size_t rightSpace = maxLength - leftSpace - sStr.size();
2533 sStr.insert(0, leftSpace, ' ');
2534 sStr.append(rightSpace, ' ');
2535 }
2536
2537
2538 // Append the string with the justified result
2539 result.push_back(sStr);
2540 }
2541
2542 return result;
2543}
2544
2545
2555{
2556 StringVector sError;
2559 return sError;
2560}
2561
2562
2572{
2573 static std::string sBUILDDATE = std::string(AutoVersion::YEAR) + "-" + AutoVersion::MONTH + "-" + AutoVersion::DATE;
2574 static std::string sINTVERSION = toString((int)AutoVersion::MAJOR) + "."
2575 + toString((int)AutoVersion::MINOR) + "."
2576 + toString((int)AutoVersion::BUILD) + "."
2577 + toString((int)(std::stod(AutoVersion::UBUNTU_VERSION_STYLE)*100));
2578 static std::string sINSTNAME = toString((int)AutoVersion::MAJOR) + toString((int)AutoVersion::MINOR) + toString((int)AutoVersion::BUILD)
2579 + (std::string(AutoVersion::STATUS_SHORT).find("rc") != std::string::npos ? AutoVersion::STATUS_SHORT : "");
2580
2581 StringVector sVersionInfo;
2582 sVersionInfo.push_back("Version");
2583 sVersionInfo.push_back(sVersion);
2584 sVersionInfo.push_back("BuildDate");
2585 sVersionInfo.push_back(sBUILDDATE);
2586 sVersionInfo.push_back("FullVersion");
2587 sVersionInfo.push_back(sINTVERSION);
2588 sVersionInfo.push_back("FileVersion");
2589 sVersionInfo.push_back(sINSTNAME);
2590
2591 return sVersionInfo;
2592}
2593
2594
2604{
2606
2607 StringVector sFileInfo;
2608 sFileInfo.push_back("Drive");
2609 sFileInfo.push_back(fInfo.drive);
2610 sFileInfo.push_back("Path");
2611 sFileInfo.push_back(fInfo.path);
2612 sFileInfo.push_back("Name");
2613 sFileInfo.push_back(fInfo.name);
2614 sFileInfo.push_back("FileExt");
2615 sFileInfo.push_back(fInfo.ext);
2616 sFileInfo.push_back("Size");
2617 sFileInfo.push_back(fInfo.filesize);
2618
2619 std::string sAttr = fInfo.fileAttributes & FileInfo::ATTR_READONLY ? "readonly," : "";
2620 sAttr += fInfo.fileAttributes & FileInfo::ATTR_HIDDEN ? "hidden," : "";
2621 sAttr += fInfo.fileAttributes & FileInfo::ATTR_SYSTEM ? "systemfile," : "";
2622 sAttr += fInfo.fileAttributes & FileInfo::ATTR_DIRECTORY ? "directory," : "";
2623 //sAttr += fInfo.fileAttributes & FileInfo::ATTR_ARCHIVE ? "archive," : "";
2624 //sAttr += fInfo.fileAttributes & FileInfo::ATTR_DEVICE ? "device," : "";
2625 sAttr += fInfo.fileAttributes & FileInfo::ATTR_TEMPORARY ? "temp," : "";
2626 sAttr += fInfo.fileAttributes & FileInfo::ATTR_COMPRESSED ? "compressed," : "";
2627 sAttr += fInfo.fileAttributes & FileInfo::ATTR_OFFLINE ? "offline," : "";
2628 sAttr += fInfo.fileAttributes & FileInfo::ATTR_ENCRYPTED ? "encrypted," : "";
2629
2630 if (sAttr.length())
2631 sAttr.pop_back();
2632 else
2633 sAttr = "none";
2634
2635 sFileInfo.push_back("Attributes");
2636 sFileInfo.push_back(sAttr);
2637 sFileInfo.push_back("CreationTime");
2638 sFileInfo.push_generic(toCmdString(fInfo.creationTime));
2639 sFileInfo.push_back("ModificationTime");
2640 sFileInfo.push_generic(toCmdString(fInfo.modificationTime));
2641
2642 return sFileInfo;
2643}
2644
2645
2655{
2656 if (funcArgs.nArg1 == DEFAULT_NUM_ARG)
2657 return "\"" + sha256(funcArgs.sArg1.view().to_string()) + "\"";
2658 else if (funcArgs.nArg1 == 1)
2659 {
2660 std::string sFileName = NumeReKernel::getInstance()->getFileSystem().ValidFileName(funcArgs.sArg1.view().to_string(),
2661 ".dat", false, true);
2662
2663 // Ensure that the file actually exist
2664 if (fileExists(sFileName))
2665 {
2666 std::fstream file(sFileName, std::ios_base::in | std::ios_base::binary);
2667 return "\"" + sha256(file) + "\"";
2668 }
2669 }
2670
2671 return "\"\"";
2672}
2673
2684static std::map<std::string, StringFuncHandle> getStringFuncHandles()
2685{
2686 std::map<std::string, StringFuncHandle> mHandleTable;
2687
2688 mHandleTable["and"] = StringFuncHandle(VAL, strfnc_and, true);
2689 mHandleTable["ascii"] = StringFuncHandle(STR, strfnc_ascii, false);
2690 mHandleTable["basetodec"] = StringFuncHandle(STR_STR, strfnc_basetodec, false);
2691 mHandleTable["char"] = StringFuncHandle(STR_VAL, strfnc_char, false);
2692 mHandleTable["cnt"] = StringFuncHandle(STR, strfnc_cnt, true);
2693 mHandleTable["dectobase"] = StringFuncHandle(STR_VAL, strfnc_dectobase, false);
2694 mHandleTable["findfile"] = StringFuncHandle(STR_STROPT, strfnc_findfile, false);
2695 mHandleTable["findparam"] = StringFuncHandle(STR_STR_STROPT, strfnc_findparam, false);
2696 mHandleTable["findtoken"] = StringFuncHandle(STR_STR_STROPT, strfnc_findtoken, false);
2697 mHandleTable["getenvvar"] = StringFuncHandle(STR, strfnc_getenvvar, false);
2698 mHandleTable["getfilelist"] = StringFuncHandle(STR_VALOPT, strfnc_getfilelist, false);
2699 mHandleTable["getfileparts"] = StringFuncHandle(STR, strfnc_getFileParts, false);
2700 mHandleTable["getfolderlist"] = StringFuncHandle(STR_VALOPT, strfnc_getfolderlist, false);
2701 mHandleTable["getkeyval"] = StringFuncHandle(STR_STR_STR_VALOPT_VALOPT, strfnc_getkeyval, true);
2702 mHandleTable["getfileinfo"] = StringFuncHandle(STR, strfnc_getfileinfo, false);
2703 mHandleTable["getlasterror"] = StringFuncHandle(NOARGS, strfnc_getlasterror, false);
2704 mHandleTable["getmatchingparens"] = StringFuncHandle(STR, strfnc_getmatchingparens, false);
2705 mHandleTable["getversioninfo"] = StringFuncHandle(NOARGS, strfnc_getversioninfo, false);
2706 mHandleTable["getopt"] = StringFuncHandle(STR_VAL, strfnc_getopt, false);
2707 mHandleTable["idxtolog"] = StringFuncHandle(VAL, strfnc_idxtolog, true);
2708 mHandleTable["is_alnum"] = StringFuncHandle(STR, strfnc_isalnum, false);
2709 mHandleTable["is_alpha"] = StringFuncHandle(STR, strfnc_isalpha, false);
2710 mHandleTable["is_blank"] = StringFuncHandle(STR, strfnc_isblank, false);
2711 mHandleTable["is_cntrl"] = StringFuncHandle(STR, strfnc_iscntrl, false);
2712 mHandleTable["is_digit"] = StringFuncHandle(STR, strfnc_isdigit, false);
2713 mHandleTable["is_dirpath"] = StringFuncHandle(STR, strfnc_isdir, false);
2714 mHandleTable["is_filepath"] = StringFuncHandle(STR, strfnc_isfile, false);
2715 mHandleTable["is_graph"] = StringFuncHandle(STR, strfnc_isgraph, false);
2716 mHandleTable["is_lower"] = StringFuncHandle(STR, strfnc_islower, false);
2717 mHandleTable["is_print"] = StringFuncHandle(STR, strfnc_isprint, false);
2718 mHandleTable["is_punct"] = StringFuncHandle(STR, strfnc_ispunct, false);
2719 mHandleTable["is_space"] = StringFuncHandle(STR, strfnc_isspace, false);
2720 mHandleTable["is_upper"] = StringFuncHandle(STR, strfnc_isupper, false);
2721 mHandleTable["is_xdigit"] = StringFuncHandle(STR, strfnc_isxdigit, false);
2722 mHandleTable["justify"] = StringFuncHandle(STR_VAL, strfnc_justify, true);
2723 mHandleTable["locate"] = StringFuncHandle(STR_STR_VALOPT_VALOPT, strfnc_locate, true);
2724 mHandleTable["logtoidx"] = StringFuncHandle(STR, strfnc_logtoidx, true);
2725 mHandleTable["max"] = StringFuncHandle(STR, strfnc_max, true);
2726 mHandleTable["min"] = StringFuncHandle(STR, strfnc_min, true);
2727 mHandleTable["num"] = StringFuncHandle(STR, strfnc_num, true);
2728 mHandleTable["or"] = StringFuncHandle(VAL, strfnc_or, true);
2729 mHandleTable["regex"] = StringFuncHandle(STR_STR_VALOPT_VALOPT, strfnc_regex, false);
2730 mHandleTable["repeat"] = StringFuncHandle(STR_VAL, strfnc_repeat, false);
2731 mHandleTable["replace"] = StringFuncHandle(STR_VAL_VALOPT_STROPT, strfnc_replace, false);
2732 mHandleTable["replaceall"] = StringFuncHandle(STR_STR_STR_VALOPT_VALOPT, strfnc_replaceall, false);
2733 mHandleTable["sha256"] = StringFuncHandle(STR_VALOPT, strfnc_sha256, false);
2734 mHandleTable["split"] = StringFuncHandle(STR_STR, strfnc_split, false);
2735 mHandleTable["str_not_match"] = StringFuncHandle(STR_STR_VALOPT, strfnc_str_not_match, false);
2736 mHandleTable["str_not_rmatch"] = StringFuncHandle(STR_STR_VALOPT, strfnc_str_not_rmatch, false);
2737 mHandleTable["strip"] = StringFuncHandle(STR_STR_STR_VALOPT_VALOPT, strfnc_strip, false);
2738 mHandleTable["strfnd"] = StringFuncHandle(STR_STR_VALOPT, strfnc_strfnd, false);
2739 mHandleTable["strfndall"] = StringFuncHandle(STR_STR_VALOPT_VALOPT, strfnc_strfndall, false);
2740 mHandleTable["strlen"] = StringFuncHandle(STR, strfnc_strlen, false);
2741 mHandleTable["strmatch"] = StringFuncHandle(STR_STR_VALOPT, strfnc_strmatch, false);
2742 mHandleTable["strmatchall"] = StringFuncHandle(STR_STR_VALOPT_VALOPT, strfnc_strmatchall, false);
2743 mHandleTable["strrfnd"] = StringFuncHandle(STR_STR_VALOPT, strfnc_strrfnd, false);
2744 mHandleTable["strrmatch"] = StringFuncHandle(STR_STR_VALOPT, strfnc_strrmatch, false);
2745 mHandleTable["strunique"] = StringFuncHandle(STR_VALOPT, strfnc_strunique, true);
2746 mHandleTable["sum"] = StringFuncHandle(STR, strfnc_sum, true);
2747 mHandleTable["substr"] = StringFuncHandle(STR_VAL_VALOPT, strfnc_substr, false);
2748 mHandleTable["textparse"] = StringFuncHandle(STR_STR_VALOPT_VALOPT, strfnc_textparse, false);
2749 mHandleTable["timeformat"] = StringFuncHandle(STR_DBL, strfnc_timeformat, false);
2750 mHandleTable["to_char"] = StringFuncHandle(VAL, strfnc_to_char, true);
2751 mHandleTable["to_lowercase"] = StringFuncHandle(STR, strfnc_to_lowercase, false);
2752 mHandleTable["to_string"] = StringFuncHandle(STR, strfnc_to_string, false);
2753 mHandleTable["to_tex"] = StringFuncHandle(DBL_VALOPT, strfnc_to_tex, false);
2754 mHandleTable["to_time"] = StringFuncHandle(STR_STR, strfnc_to_time, false);
2755 mHandleTable["to_uppercase"] = StringFuncHandle(STR, strfnc_to_uppercase, false);
2756 mHandleTable["weekday"] = StringFuncHandle(DBL_VALOPT, strfnc_weekday, false);
2757 mHandleTable["xor"] = StringFuncHandle(VAL, strfnc_xor, true);
2758
2759 return mHandleTable;
2760}
2761
2762
2763
2764
const std::string sVersion
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
std::vector< std::string > getFileParts(const std::string &sFilePath) const
This member function separates all path parts into single strings: the drive letter,...
Definition: filesystem.cpp:566
FileInfo getFileInfo(const std::string &sFilePath) const
Return the file information about the passed file path.
Definition: filesystem.cpp:642
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
Definition: filesystem.cpp:280
void setTokens(std::string _sTokens)
This member function may be used to update the path placeholders of the current FileSystem instance.
Definition: filesystem.cpp:694
void declareFileType(const std::string &sFileType)
Definition: filesystem.hpp:132
int setPath(std::string _sPath, bool bMkDir, std::string _sExePath)
This member function may be used to set the preferred file path of the current FileSystem instance.
Definition: filesystem.cpp:443
std::vector< std::string > getList(const std::string &sMessageScheme) const
This member function returns a vector of language strings matching to the passed identifier containin...
Definition: language.cpp:349
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
FileSystem & getFileSystem()
Definition: kernel.hpp:258
static void issueWarning(std::string sWarningMessage)
This static function may be used to issue a warning to the user. The warning will be printed by the t...
Definition: kernel.cpp:2833
Settings & getSettings()
Definition: kernel.hpp:296
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
Definition: settings.hpp:1000
std::string getTokenPaths() const
Returns a semicolon-separated list of the current defined path placeholders and their values.
Definition: settings.hpp:1122
std::string getExePath() const
Returns the current application root folder path.
Definition: settings.hpp:1010
StringView view() const
Get a view to the contained string.
bool is_string() const
Determine, whether the contained string represents a string literal.
std::string & getRef()
Get a reference to the contained string.
This class is an extension to the std::vector<std::string> to provide the vector-like functionalities...
void push_back(const std::string &sStr)
Append a string to the end of this vector. Will be stored as local string.
std::string & getRef(size_t i)
Return a reference to the i-th element in this string.
static StringVector empty_string()
Static member function to create a StringVector with one component with zero length.
void push_generic(const std::string &sStr)
Append a generic string value to the end of this vector. Depending on the existence of surrounding qu...
bool is_string(size_t i) const
Check whether the i-th element represents a string or a numeric value.
size_t rfind(const std::string &findstr, size_t pos=std::string::npos) const
Wrapper member function for std::string::rfind()
void strip()
This member function shrinks the viewed section to remove all leading or trailing whitespace characte...
void trim_front(size_t len)
This member function can be used to remove characters from the front of the viewed section.
size_t find_first_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_of()
size_t find_last_of(const std::string &findstr, size_t pos=std::string::npos) const
Wrapper member function for std::string::find_last_of()
size_t find_last_not_of(const std::string &findstr, size_t pos=std::string::npos) const
Wrapper member function for std::string::find_last_not_of()
const char & front() const
This member function provides a const char reference to the first character in the viewed section.
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
void trim_back(size_t len)
This member function can be used to remove characters from the back of the viewed section.
size_t find(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find()
size_t length() const
This member function simply returns the length of the viewed section.
size_t find_first_not_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_not_of()
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ INVALID_REGEX
Definition: error.hpp:139
static size_t invalid_position
Definition: error.hpp:235
CONSTCD11 date::year year() const NOEXCEPT
Definition: date.h:2928
CONSTCD11 date::day day() const NOEXCEPT
Definition: date.h:2930
CONSTCD11 date::month month() const NOEXCEPT
Definition: date.h:2929
Language _lang
Definition: kernel.cpp:39
size_t getWeekDay(sys_time_point tp)
Returns the weekday of the selected timepoint as an unsigned integer with Monday being 1u and Sunday ...
sys_time_point to_timePoint(double d)
Convert a double to a sys_time_point assuming the double is in units of seconds.
double to_double(sys_time_point tp)
Convert a sys_time_point to a double. The double is returned in units of seconds.
sys_time_point sys_time_now()
Returns the current time as a sys_time_point (i.e. a std::chrono::time_point with microseconds precis...
time_stamp getTimeStampFromTimePoint(sys_time_point tp)
Return a time_stamp instance converted from the passed sys_time_point.
time_zone getCurrentTimeZone()
Return the current time_zone of the system.
sys_time_point getTimePointFromTimeStamp(const time_stamp &ts)
Convert a time_stamp to a sys_time_point.
std::chrono::time_point< std::chrono::system_clock, std::chrono::microseconds > sys_time_point
This is a typedef for a custom system_clock time_point with microseconds precision.
std::string errorTypeToString(ErrorType e)
Return the error type converted to a human readable string.
Definition: error.cpp:148
std::string getLastErrorMessage()
Return the last error message, which was catched by the getErrorType() function.
Definition: error.cpp:121
ErrorType getLastErrorType()
Return the last error type, which was catched by the getErrorType() function.
Definition: error.cpp:134
bool is_file(std::string sPathname)
This function checks whether a given string is a valid file path.
Definition: filecheck.cpp:67
bool is_dir(std::string sPathname)
This function checks whether a given string is a valid directory path.
Definition: filecheck.cpp:37
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
Definition: tools.cpp:2500
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
Definition: tools.cpp:414
std::complex< double > intPower(const std::complex< double > &, int)
This function calculates the power of a value with the specialization that the exponent is an integer...
Definition: tools.cpp:3640
static const long MINOR
Definition: version.h:18
static const long BUILD
Definition: version.h:19
static const char DATE[]
Definition: version.h:7
static const long MAJOR
Definition: version.h:17
static const char MONTH[]
Definition: version.h:8
static const char YEAR[]
Definition: version.h:9
static const char STATUS_SHORT[]
Definition: version.h:14
static const char UBUNTU_VERSION_STYLE[]
Definition: version.h:10
CONSTDATA date::month oct
Definition: date.h:2000
sys_time< days > sys_days
Definition: date.h:193
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int StrToInt(const std::string &)
Converts a string into an integer.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
Definition: tools.cpp:113
@ STR_STR_VALOPT
@ STR_STR_VALOPT_VALOPT
@ STR_VAL_VALOPT
@ STR_STR_STR_VALOPT_VALOPT
@ STR_VAL_VALOPT_STROPT
@ STR_STR_STROPT
static StringVector strfnc_getfolderlist(StringFuncArgs &funcArgs)
Implementation of the getfolderlist() function.
static StringVector strfnc_str_not_rmatch(StringFuncArgs &funcArgs)
Implementation of the str_not_rmatch() function.
static StringVector strfnc_timeformat(StringFuncArgs &funcArgs)
Implementation of the timeformat() function.
static StringVector strfnc_isblank(StringFuncArgs &funcArgs)
Implementation of the is_blank() function.
static StringVector strfnc_getversioninfo(StringFuncArgs &funcArgs)
Implementation of the getversioninfo() function.
static StringVector strfnc_to_char(StringFuncArgs &funcArgs)
Implementation of the to_char() function.
static StringVector strfnc_strrfnd(StringFuncArgs &funcArgs)
Implementation of the strrfnd() function.
static StringVector strfnc_strfndall(StringFuncArgs &funcArgs)
Implementation of the strfndall() function.
static StringVector strfnc_regex(StringFuncArgs &funcArgs)
Implementation of the regex() function.
static StringVector strfnc_strunique(StringFuncArgs &funcArgs)
Implementation of the strunique() function.
static std::map< std::string, StringFuncHandle > getStringFuncHandles()
This static function is used to construct the string map.
static StringVector strfnc_strrmatch(StringFuncArgs &funcArgs)
Implementation of the strrmatch() function.
static StringVector strfnc_basetodec(StringFuncArgs &funcArgs)
Implementation of the basetodec() function.
static StringVector strfnc_dectobase(StringFuncArgs &funcArgs)
Implementation of the dectobase() function.
static StringVector strfnc_isxdigit(StringFuncArgs &funcArgs)
Implementation of the is_xdigit() function.
static StringVector strfnc_islower(StringFuncArgs &funcArgs)
Implementation of the is_lower() function.
static StringVector strfnc_getfilelist(StringFuncArgs &funcArgs)
Implementation of the getfilelist() function.
static StringVector strfnc_isprint(StringFuncArgs &funcArgs)
Implementation of the is_print() function.
static StringVector strfnc_iscntrl(StringFuncArgs &funcArgs)
Implementation of the is_cntrl() function.
static StringVector strfnc_and(StringFuncArgs &funcArgs)
Implementation of the and() function.
static StringVector strfnc_max(StringFuncArgs &funcArgs)
Implementation of the max() function.
static StringVector strfnc_locate(StringFuncArgs &funcArgs)
Implementation of the locate() function.
string removeQuotationMarks(const std::string &sString)
This function simply removes the surrounding quotation marks.
static StringVector strfnc_strfnd(StringFuncArgs &funcArgs)
Implementation of the strfnd() function.
static StringVector strfnc_repeat(StringFuncArgs &funcArgs)
Implementation of the repeat() function.
static StringVector strfnc_isalnum(StringFuncArgs &funcArgs)
Implementation of the is_alnum() function.
static std::string formatNumberToTex(const mu::value_type &number, size_t precision=0)
This function converts a number into a tex string.
static StringVector strfnc_str_not_match(StringFuncArgs &funcArgs)
Implementation of the str_not_match() function.
static StringVector strfnc_weekday(StringFuncArgs &funcArgs)
Implementation of the weekday() function.
static StringVector strfnc_xor(StringFuncArgs &funcArgs)
Implementation of the xor() function.
static StringVector strfnc_isfile(StringFuncArgs &funcArgs)
Implementation of the is_file() function.
static StringVector strfnc_to_time(StringFuncArgs &funcArgs)
Implementation of the to_time() function.
static StringVector strfnc_num(StringFuncArgs &funcArgs)
Implementation of the num() function.
static StringVector strfnc_findtoken(StringFuncArgs &funcArgs)
Implementation of the findtoken() function.
static StringVector strfnc_or(StringFuncArgs &funcArgs)
Implementation of the or() function.
static StringVector strfnc_findfile(StringFuncArgs &funcArgs)
Implementation of the findfile() function.
static double extractLaTeXExponent(std::string &sExpr)
Simple helper to parse the exponents in LaTeX format.
static StringVector strfnc_substr(StringFuncArgs &funcArgs)
Implementation of the substr() function.
static StringVector strfnc_split(StringFuncArgs &funcArgs)
Implementation of the split() function.
static StringVector strfnc_to_tex(StringFuncArgs &funcArgs)
Implementation of the to_tex() function.
static StringVector strfnc_isupper(StringFuncArgs &funcArgs)
Implementation of the is_upper() function.
static StringVector strfnc_getkeyval(StringFuncArgs &funcArgs)
Implementation of the getkeyval() function.
static long long int convertBaseToDecimal(StringView value, NumberBase base)
Static helper function for converting number bases into the decimal base.
static StringVector strfnc_sum(StringFuncArgs &funcArgs)
Implementation of the sum() function.
static StringVector strfnc_cnt(StringFuncArgs &funcArgs)
Implementation of the cnt() function.
#define DEFAULT_NUM_ARG
static StringVector strfnc_isgraph(StringFuncArgs &funcArgs)
Implementation of the is_graph() function.
static StringVector strfnc_getenvvar(StringFuncArgs &funcArgs)
Implementation of the getenvvar() function.
static StringVector strfnc_to_string(StringFuncArgs &funcArgs)
Implementation of the to_string() function.
static StringVector strfnc_strmatch(StringFuncArgs &funcArgs)
Implementation of the strmatch() function.
static StringVector strfnc_replace(StringFuncArgs &funcArgs)
Implementation of the replace() function.
static StringVector strfnc_strip(StringFuncArgs &funcArgs)
Implementation of the strip() function.
static StringVector strfnc_findparam(StringFuncArgs &funcArgs)
Implementation of the findparam() function.
static StringVector strfnc_char(StringFuncArgs &funcArgs)
Implementation of the char() function.
static StringVector strfnc_isalpha(StringFuncArgs &funcArgs)
Implementation of the is_alpha() function.
static StringVector strfnc_isdir(StringFuncArgs &funcArgs)
Implementation of the is_dir() function.
static StringVector strfnc_min(StringFuncArgs &funcArgs)
Implementation of the min() function.
static std::string createLaTeXExponent(const std::string &sExp, bool negative)
Simple helper to create a LaTeX exponent from a string.
static StringVector strfnc_justify(StringFuncArgs &funcArgs)
Implementation of the justify function. Each string in a std::vector of strings is filled with whites...
static StringVector strfnc_getlasterror(StringFuncArgs &funcArgs)
Implementation of the getlasterror() function.
static StringVector strfnc_getopt(StringFuncArgs &funcArgs)
Implementation of the getopt() function.
static StringVector strfnc_ascii(StringFuncArgs &funcArgs)
Implementation of the ascii() function.
static StringVector strfnc_idxtolog(StringFuncArgs &funcArgs)
Implementation of the idxtolog() function.
static StringVector strfnc_isspace(StringFuncArgs &funcArgs)
Implementation of the is_space() function.
static StringVector strfnc_strmatchall(StringFuncArgs &funcArgs)
Implementation of the strmatchall() function.
static StringVector strfnc_replaceall(StringFuncArgs &funcArgs)
Implementation of the replaceall() function.
static StringVector strfnc_logtoidx(StringFuncArgs &funcArgs)
Implementation of the logtoidx() function.
static StringVector strfnc_sha256(StringFuncArgs &funcArgs)
Implementation of the sha256() function.
static StringVector strfnc_strlen(StringFuncArgs &funcArgs)
Implementation of the strlen() function.
static StringVector strfnc_to_lowercase(StringFuncArgs &funcArgs)
Implementation of the to_lowercase() function.
static std::string padWithZeros(int nTime, size_t nLength)
Creates a padding string full of 0.
string removeMaskedStrings(const std::string &sString)
This function removes the escape characters from the passed string.
static StringVector strfnc_getFileParts(StringFuncArgs &funcArgs)
Implementation of the getfileparts() function.
static StringVector strfnc_to_uppercase(StringFuncArgs &funcArgs)
Implementation of the to_uppercase() function.
static StringVector strfnc_isdigit(StringFuncArgs &funcArgs)
Implementation of the is_digit() function.
static StringVector strfnc_getmatchingparens(StringFuncArgs &funcArgs)
Implementation of the getmatchinparens() function.
string addQuotationMarks(const std::string &sString)
This function simply adds the surrounding quotation marks.
static StringVector strfnc_ispunct(StringFuncArgs &funcArgs)
Implementation of the is_punct() function.
static StringVector strfnc_getfileinfo(StringFuncArgs &funcArgs)
Implementation of the getfileinfo() function.
static StringVector strfnc_textparse(StringFuncArgs &funcArgs)
Implementation of the textparse() function.
sys_time_point StrToTime(const std::string &sString)
Convert a string to a sys_time_point.
bool isConvertible(const std::string &sStr, ConvertibleType type)
This function checks, whether a string can be converted to the selected ConvertibleType.
std::complex< double > StrToCmplx(const std::string &sString)
Converts a string into a complex number.
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
std::string toCmdString(double dNumber)
Converts a numerical value into a "full" precision string.
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
@ CONVTYPE_DATE_TIME
Definition: stringtools.hpp:45
@ CONVTYPE_VALUE
Definition: stringtools.hpp:44
This structure contains all relevant information about a file path.
Definition: filesystem.hpp:41
std::string path
Definition: filesystem.hpp:43
size_t filesize
Definition: filesystem.hpp:46
double creationTime
Definition: filesystem.hpp:48
double modificationTime
Definition: filesystem.hpp:49
@ ATTR_ENCRYPTED
Definition: filesystem.hpp:66
@ ATTR_COMPRESSED
Definition: filesystem.hpp:63
@ ATTR_OFFLINE
Definition: filesystem.hpp:64
@ ATTR_READONLY
Definition: filesystem.hpp:53
@ ATTR_DIRECTORY
Definition: filesystem.hpp:56
@ ATTR_TEMPORARY
Definition: filesystem.hpp:60
std::string drive
Definition: filesystem.hpp:42
size_t fileAttributes
Definition: filesystem.hpp:47
std::string ext
Definition: filesystem.hpp:45
std::string name
Definition: filesystem.hpp:44
This structure combines all string function's arguments into a single structure to align all string f...
const Settings * opt
This structure defines the internal string function signature. It contains the pointer to the actual ...
Structure containing the german umlauts. The lower field will contain lower case umlauts,...
std::string upper
std::string lower
This structure defines all fields necessary to create a time stamp or a formatted date.
date::year_month_day m_ymd
std::chrono::microseconds m_microsecs
std::chrono::minutes m_minutes
std::chrono::seconds m_seconds
std::chrono::hours m_hours
std::chrono::milliseconds m_millisecs
This structure defines the information for a time zone.
std::string toString(int)
Converts an integer to a string without the Settings bloat.
vector< string > getFileList(const string &sDirectory, const Settings &_option, int nFlags)
This function returns a list of files (including their paths, if nFlags & 1).
Definition: tools.cpp:2853
string getArgAtPos(const string &sCmd, unsigned int nPos, int extraction)
Extracts a options value at the selected position and applies automatic parsing, if necessary.
Definition: tools.cpp:1598
vector< string > getFolderList(const string &sDirectory, const Settings &_option, int nFlags)
This function returns a list of directories (including their paths, if nFlags & 1).
Definition: tools.cpp:2925