Text.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. #pragma once
  2. #include <functional>
  3. #include <sstream>
  4. #include "Reader.h"
  5. #include "ReferenceCounter.h"
  6. namespace Framework
  7. {
  8. namespace SpecialCharacters
  9. {
  10. const char SMALL_UE = '\xFC';
  11. const char BIG_UE = '\xDC';
  12. const char SMALL_AE = '\xE4';
  13. const char BIG_AE = '\xC4';
  14. const char SMALL_OE = '\xF6';
  15. const char BIG_OE = '\xD6';
  16. const char SZ = '\xDF';
  17. const char DEGREE_SIGN = '\xB0';
  18. const char CARET = '\x5E';
  19. const char SECTION_SIGN = '\xA7';
  20. const char ACUTE_ACCENT = '\xB4';
  21. } // namespace SpecialCharacters
  22. namespace Regex
  23. {
  24. class Result;
  25. class RegexConfig;
  26. } // namespace Regex
  27. class DynamicBuffer : public std::stringbuf
  28. {
  29. private:
  30. std::function<int(std::stringbuf&)> onAppend;
  31. public:
  32. DLLEXPORT DynamicBuffer(std::function<int(std::stringbuf&)> onAppend);
  33. DLLEXPORT virtual int sync() override;
  34. };
  35. class FlushingOStream : public std::ostream
  36. {
  37. private:
  38. std::function<void()> onDestroy;
  39. public:
  40. DLLEXPORT FlushingOStream(
  41. DynamicBuffer* buffer, std::function<void()> onDestroy = []() {});
  42. DLLEXPORT FlushingOStream(const Framework::FlushingOStream& stream);
  43. DLLEXPORT ~FlushingOStream();
  44. };
  45. //! A replacement for String
  46. class Text : public virtual ReferenceCounter
  47. {
  48. private:
  49. char* txt;
  50. int length;
  51. char suchGBeg;
  52. char suchGEnd;
  53. int precision;
  54. DynamicBuffer* stringWriter;
  55. DLLEXPORT Text(char* txt, int l);
  56. public:
  57. //! Creates a new Text object with the value ""
  58. DLLEXPORT Text();
  59. //! Creates a new Text object by copying the value from (txt)
  60. //! \param txt The text to be copied
  61. DLLEXPORT Text(const Text& txt);
  62. //! Creates a new Text object by copying the value from (txt)
  63. //! \param txt The string to be copied
  64. DLLEXPORT Text(const char* txt);
  65. //! Creates a new Text object by copying a section from (txt)
  66. //! \param txt The string from which a section should be copied
  67. //! \param offset Start position from which to copy
  68. //! \param length Number of characters to copy
  69. DLLEXPORT Text(const char* txt, int offset, int length);
  70. //! Creates a new Text object with a number as text
  71. //! \param zahl The number to be contained in the text
  72. DLLEXPORT Text(int zahl);
  73. //! Creates a new Text object with a number as text
  74. //! \param num The number to be contained in the text
  75. DLLEXPORT Text(double num);
  76. //! Creates a new Text object with a number as text
  77. //! \param num The number to be contained in the text
  78. DLLEXPORT Text(float num);
  79. //! Deletes the text
  80. DLLEXPORT ~Text();
  81. private:
  82. DLLEXPORT void setTextZ(char* t, int l);
  83. public:
  84. //! Converts all letters to uppercase
  85. DLLEXPORT void toUpperCase();
  86. //! Converts all letters to lowercase
  87. DLLEXPORT void toLowerCase();
  88. //! Sets the search boundaries used by the search functions
  89. //! \param gBeg The character at which the search should begin
  90. //! \param gEnd The character at which the search should end
  91. DLLEXPORT void setSuchGrenzen(char gBeg, char gEnd);
  92. //! Sets the text stored by this object
  93. //! \param t A string whose content is copied
  94. DLLEXPORT void setText(const char* t);
  95. //! Sets the text stored by this object
  96. //! \param t A string whose content is copied
  97. //! \param l The length of the text to be copied from (t)
  98. DLLEXPORT void setText(const char* t, int l);
  99. //! Sets the text stored by this object
  100. //! \param t The Text object whose content should be copied
  101. DLLEXPORT void setText(const Text& t);
  102. //! Appends the given number as hex text (0-F) to the end of the text
  103. //! \param num The number to be converted to hex and appended
  104. DLLEXPORT void appendHex(char num);
  105. //! Appends the given number as hex text (0-F) to the end of the text
  106. //! \param num The number to be converted to hex and appended
  107. DLLEXPORT void appendHex(short num);
  108. //! Appends the given number as hex text (0-F) to the end of the text
  109. //! \param num The number to be converted to hex and appended
  110. DLLEXPORT void appendHex(int num);
  111. //! Appends the given number as hex text (0-F) to the end of the text
  112. //! \param num The number to be converted to hex and appended
  113. DLLEXPORT void appendHex(__int64 num);
  114. //! Appends the given character to the string
  115. //! \param c The character to be appended
  116. DLLEXPORT void append(char c);
  117. //! Appends the given string to the end of the text
  118. //! \param t The string whose copy should be appended to the end of the
  119. //! text
  120. DLLEXPORT void append(const char* t);
  121. //! Appends a part of the given string to the end of the text
  122. //! \param t The string whose copy should be appended
  123. //! \param l The length of the text section to be appended
  124. DLLEXPORT void append(const char* t, int l);
  125. //! Appends the content of a Text to the end of the text
  126. //! \param t The Text whose copy should be appended to the end of the
  127. //! text
  128. DLLEXPORT void append(const Text& t);
  129. //! Appends a number to the end of the text
  130. //! \param num The number to be converted to text and appended at the
  131. //! end
  132. DLLEXPORT void append(int num);
  133. //! Appends a number to the end of the text
  134. //! \param num The number to be converted to text and appended at the
  135. //! end
  136. DLLEXPORT void append(__int64 num);
  137. //! Appends an unsigned number to the end of the text
  138. //! \param num The number to be converted to text and appended at the
  139. //! end
  140. DLLEXPORT void append(unsigned int num);
  141. //! Appends a floating-point number to the end of the text
  142. //! \param num The floating-point number to be appended to the end of
  143. //! the text
  144. DLLEXPORT void append(double num);
  145. //! Appends a floating-point number to the end of the text
  146. //! \param num The floating-point number to be appended to the end of
  147. //! the text
  148. DLLEXPORT void append(float num);
  149. //! Returns an ostream that appends all output to this text
  150. DLLEXPORT FlushingOStream append();
  151. //! Inserts a character at a specific position in the text
  152. //! \param p The position in the text where the character should be
  153. //! inserted
  154. //! \param c The character to be inserted
  155. DLLEXPORT void insert(int p, char c);
  156. //! Inserts a string at a specific position in the text
  157. //! \param p The position in the text where the string should be
  158. //! inserted
  159. //! \param t The string whose copy should be inserted
  160. DLLEXPORT void insert(int p, const char* t);
  161. //! Inserts a string at a specific position in the text
  162. //! \param p The position in the text where the string should be
  163. //! inserted
  164. //! \param t The string whose copy should be inserted
  165. //! \param len The length of the text to be inserted
  166. DLLEXPORT void insert(int p, const char* t, int len);
  167. //! Inserts the content of a Text at a specific position in the text
  168. //! \param p The position in the text where the content should be
  169. //! inserted
  170. //! \param t The Text whose copy should be inserted at the position
  171. DLLEXPORT void insert(int p, const Text& t);
  172. // replaces all regular expression occurences by a static string
  173. // \param regex The regular expression to search for
  174. // \param replacement The string to replace the occurences with
  175. // \param config The configuration for the regular expression
  176. DLLEXPORT void regexReplace(const char* regex,
  177. const char* replacement,
  178. Regex::RegexConfig* config = 0);
  179. // replaces all regular expression occurences with a result of a
  180. // specified replacement function string \param regex The regular
  181. // expression to search for \param replacementFunction a function that
  182. // is called with the result of the regular expression and should return
  183. // the replacement string \param config The configuration for the
  184. // regular expression
  185. DLLEXPORT void regexReplace(const char* regex,
  186. std::function<Text(Regex::Result&)> replacementFunction,
  187. Regex::RegexConfig* config = 0);
  188. //! Replaces a specific text section with another string
  189. //! \param p1 The start position of the text section to be replaced
  190. //! \param p2 The end position of the text section to be replaced
  191. //! \param t The string to be copied to the corresponding position
  192. //! Example: ( "Hallo Welt" ).ersetzen( 2, 5, "lt" );
  193. //! results in: "Halt Welt"
  194. DLLEXPORT void ersetzen(int p1, int p2, const char* t);
  195. //! Replaces a specific text section with another string
  196. //! \param p1 The start position of the text section to be replaced
  197. //! \param p2 The end position of the text section to be replaced
  198. //! \param t The string to be copied to the corresponding position
  199. //! \param len The length of the text to be copied to the corresponding
  200. //! position Example: ( "Hallo Welt" ).ersetzen( 2, 5, "lt", 2 );
  201. //! results in: "Halt Welt"
  202. DLLEXPORT void ersetzen(int p1, int p2, const char* t, int len);
  203. //! Replaces a specific text section with the content of another Text
  204. //! p1: The start position of the text section to be replaced
  205. //! p2: The end position of the text section to be replaced
  206. //! \param t The Text whose content should be copied to the
  207. //! corresponding position Example: ( "Hallo Welt" ).ersetzen( 2, 5, new
  208. //! Text( "lt" ) ); results in: "Halt Welt"
  209. DLLEXPORT void ersetzen(int p1, int p2, const Text& t);
  210. //! Searches and replaces every occurrence of a specific character with
  211. //! another
  212. //! c1: The character to be replaced
  213. //! c2: The character to replace the other one with
  214. DLLEXPORT void ersetzen(char c1, char c2);
  215. //! Searches and replaces every occurrence of a specific string with
  216. //! another
  217. //! t1: The string to be replaced
  218. //! t2: The string to replace the other one with
  219. DLLEXPORT void ersetzen(const char* t1, const char* t2);
  220. //! Searches and replaces every occurrence of a specific string with
  221. //! another
  222. //! \param t1 The string to be replaced
  223. //! \param t2 The string to replace the other one with
  224. //! \param len1 The length of the string to be replaced
  225. //! \param len2 The length of the replacement string
  226. DLLEXPORT void ersetzen(
  227. const char* t1, int len1, const char* t2, int len2);
  228. //! Searches and replaces every occurrence of the content of a Text with
  229. //! another string
  230. //! t1: The Text whose content is searched for and replaced
  231. //! t2: The string to replace the occurrences of the Text with
  232. DLLEXPORT void ersetzen(const Text& t1, const char* t2);
  233. //! Searches and replaces every occurrence of a string with the
  234. //! content of a Text
  235. //! t1: The string to be replaced
  236. //! t2: The Text whose content should replace the occurrences of the
  237. //! string
  238. DLLEXPORT void ersetzen(const char* t1, const Text& t2);
  239. //! Searches and replaces every occurrence of the content of a Text with
  240. //! the content of another Text
  241. //! t1: The Text whose occurrences should be replaced
  242. //! t2: The Text whose content should replace the occurrences
  243. DLLEXPORT void ersetzen(const Text& t1, const Text& t2);
  244. //! Replaces the i-th occurrence of a specific character with another
  245. //! character
  246. //! \param i Which occurrence of the character should be replaced
  247. //! c1: The character whose i-th occurrence should be replaced
  248. //! c2: The character to replace the i-th occurrence of the other
  249. //! character
  250. DLLEXPORT void ersetzen(int i, char c1, char c2);
  251. //! Replaces the i-th occurrence of a specific string with another
  252. //! string
  253. //! \param i Which occurrence of the string should be replaced
  254. //! c1: The string whose i-th occurrence should be replaced
  255. //! c2: The string to replace the i-th occurrence of the other string
  256. DLLEXPORT void ersetzen(int i, const char* t1, const char* t2);
  257. //! Replaces the i-th occurrence of a specific string with another
  258. //! string
  259. //! \param i Which occurrence of the string should be replaced
  260. //! \param c1 The string whose i-th occurrence should be replaced
  261. //! \param c2 The string to replace the i-th occurrence of the other
  262. //! string
  263. //! \param len1 The length of the string to be replaced
  264. //! \param len2 The length of the replacement string
  265. DLLEXPORT void ersetzen(
  266. int i, const char* t1, int len1, const char* t2, int len2);
  267. //! Replaces the i-th occurrence of the content of a Text with a string
  268. //! \param i Which occurrence of the Text should be replaced
  269. //! c1: The Text whose i-th occurrence should be replaced
  270. //! c2: The string to replace the i-th occurrence of the Text
  271. DLLEXPORT void ersetzen(int i, const Text& t1, const char* t2);
  272. //! Replaces the i-th occurrence of a specific string with the content
  273. //! of a Text
  274. //! \param i Which occurrence of the string should be replaced
  275. //! c1: The string whose i-th occurrence should be replaced
  276. //! c2: The Text whose content should replace the i-th occurrence of
  277. //! the string
  278. DLLEXPORT void ersetzen(int i, const char* t1, const Text& t2);
  279. //! Replaces the i-th occurrence of a specific Text with the content
  280. //! of another Text
  281. //! \param i Which occurrence of the Text should be replaced
  282. //! c1: The Text whose i-th occurrence should be replaced
  283. //! c2: The Text whose content should replace the i-th occurrence of
  284. //! the other Text
  285. DLLEXPORT void ersetzen(int i, const Text& t1, const Text& t2);
  286. //! Clears the current text and creates a text consisting of a specific
  287. //! character with a specific length
  288. //! \param c The character the text should consist of
  289. //! \param length The length of the text
  290. DLLEXPORT void fillText(char c, int length);
  291. //! Deletes a specific character from the text
  292. //! \param p The position of the character to be deleted
  293. DLLEXPORT void remove(int p);
  294. //! Deletes a specific text section
  295. //! p1: The start position of the section to be deleted
  296. //! p2: The end position of the section to be deleted (the character at
  297. //! p2 is preserved)
  298. DLLEXPORT void remove(int p1, int p2);
  299. //! Deletes every occurrence of a specific character
  300. //! \param c The character whose occurrences should be deleted
  301. DLLEXPORT void remove(char c);
  302. //! Deletes every occurrence of a specific string
  303. //! \param t The string whose occurrences should be removed
  304. DLLEXPORT void remove(const char* t);
  305. //! Deletes every occurrence of a specific string
  306. //! \param t The string whose occurrences should be removed
  307. //! \param len The length of the string to be deleted
  308. DLLEXPORT void remove(const char* t, int len);
  309. //! Deletes every occurrence of the content of a Text
  310. //! \param t The Text whose content should be deleted
  311. DLLEXPORT void remove(const Text& t);
  312. //! Deletes the i-th occurrence of a specific character
  313. //! \param i Which occurrence of the character should be deleted
  314. //! \param c The character whose i-th occurrence should be deleted
  315. DLLEXPORT void remove(int i, char c);
  316. //! Deletes the i-th occurrence of a specific string
  317. //! \param i Which occurrence of the string should be deleted
  318. //! \param t The string whose i-th occurrence should be deleted
  319. DLLEXPORT void remove(int i, const char* t);
  320. //! Deletes the i-th occurrence of a specific string
  321. //! \param i Which occurrence of the string should be deleted
  322. //! \param t The string whose i-th occurrence should be deleted
  323. //! \param len The length of the string to be deleted
  324. DLLEXPORT void remove(int i, const char* t, int len);
  325. //! Deletes the i-th occurrence of a specific text content
  326. //! \param i Which occurrence of the text content should be deleted
  327. //! \param t The Text whose i-th occurrence should be deleted
  328. DLLEXPORT void remove(int i, const Text& t);
  329. //! Deletes all ' ', '\n', '\r', '\t' until a non-whitespace character
  330. //! \param pos The position of the first character
  331. //! \return the number of removed characters
  332. DLLEXPORT int removeWhitespaceAfter(int pos);
  333. //! Deletes all ' ', '\n', '\r', '\t' until a non-whitespace character
  334. //! \param pos The position of the first character (starts at pos-1)
  335. //! \return the number of removed characters
  336. DLLEXPORT int removeWhitespaceBefore(int pos);
  337. //! Sets the number of decimal places when appending floating-point
  338. //! numbers
  339. //! \param p The number of digits after the decimal point
  340. DLLEXPORT void setPrecision(int p);
  341. //! Returns the length of the text
  342. DLLEXPORT int getLength() const;
  343. //! Determines the new cursor position after pressing the 'Left' arrow
  344. //! key
  345. //! \param pos The old cursor position
  346. DLLEXPORT int getLKick(int pos) const;
  347. //! Determines the new cursor position after pressing the 'Up' arrow key
  348. //! \param pos The old cursor position
  349. DLLEXPORT int getOKick(int pos) const;
  350. //! Determines the new cursor position after pressing the 'Right' arrow
  351. //! key
  352. //! \param pos The old cursor position
  353. DLLEXPORT int getRKick(int pos) const;
  354. //! Determines the new cursor position after pressing the 'Down' arrow
  355. //! key
  356. //! \param pos The old cursor position
  357. DLLEXPORT int getUKick(int pos) const;
  358. //! Checks whether the content of another Text occurs in the text
  359. //! \param t The Text whose content should be searched for
  360. //! \return (true) if the content of the Text is found. (false)
  361. //! otherwise
  362. DLLEXPORT bool hat(const Text& t) const;
  363. //! Checks whether a specific string occurs in the text
  364. //! \param t The string to search for
  365. //! \return (true) if the string is found. (false) otherwise
  366. DLLEXPORT bool hat(const char* t) const;
  367. //! Checks whether a specific string occurs in the text
  368. //! \param t The string to search for
  369. //! \param len The length of the string to search for
  370. //! \return (true) if the string is found. (false) otherwise
  371. DLLEXPORT bool hat(const char* t, int len) const;
  372. //! Checks whether a specific string occurs in the text
  373. //! \param searchStartIndex The index from which to start searching
  374. //! \param t The string to search for
  375. //! \return (true) if the string is found. (false) otherwise
  376. DLLEXPORT bool hat(int searchStartIndex, const char* t) const;
  377. //! Checks whether a specific string occurs in the text
  378. //! \param searchStartIndex The index from which to start searching
  379. //! \param t The string to search for
  380. //! \param len The length of the string to search for
  381. //! \return (true) if the string is found. (false) otherwise
  382. DLLEXPORT bool hat(int searchStartIndex, const char* t, int len) const;
  383. //! Checks whether the content of another Text occurs at a specific
  384. //! position
  385. //! \param pos The position where the string should begin in the text
  386. //! \param t The Text whose content should be searched for
  387. //! \return (true) if the content of the Text is found. (false)
  388. //! otherwise
  389. DLLEXPORT bool hatAt(int pos, const Text& t) const;
  390. //! Checks whether a specific string occurs at a specific position
  391. //! \param pos The position where the string should begin in the text
  392. //! \param t The string to search for
  393. //! \return (true) if the string is found. (false) otherwise
  394. DLLEXPORT bool hatAt(int pos, const char* t) const;
  395. //! Checks whether a specific string occurs at a specific position
  396. //! \param pos The position where the string should begin in the text
  397. //! \param t The string to search for
  398. //! \param len The length of the string to search for
  399. //! \return (true) if the string is found. (false) otherwise
  400. DLLEXPORT bool hatAt(int pos, const char* t, int len) const;
  401. //! Checks whether a specific character occurs in the text
  402. //! \param c The character to search for
  403. //! \return (true) if the character is found. (false) otherwise
  404. DLLEXPORT bool hat(char c) const;
  405. //! Checks whether the text starts with a specific string
  406. DLLEXPORT bool beginnsWith(const char* t) const;
  407. //! Checks whether the text ends with a specific string
  408. DLLEXPORT bool endsWith(const char* t) const;
  409. //! Checks whether the text has the same content as a string
  410. //! \param t The string to compare with
  411. //! \return (true) if the content of the text equals the string. (false)
  412. //! otherwise
  413. DLLEXPORT bool istGleich(const char* t) const;
  414. //! Checks whether the text has the same content as a string
  415. //! \param t The string to compare with
  416. //! \param len The length of the string to compare
  417. //! \return (true) if the content of the text equals the string. (false)
  418. //! otherwise
  419. DLLEXPORT bool istGleich(const char* t, int len) const;
  420. //! Checks whether the text has the same content as another Text
  421. //! \param t The Text whose content should be compared
  422. //! \return (true) if the contents match. (false) otherwise
  423. DLLEXPORT bool istGleich(const Text& t) const;
  424. //! Returns the content of the text as a string
  425. DLLEXPORT const char* getText() const;
  426. //! Counts how often a specific character occurs in the text
  427. //! \param c The character to be counted
  428. //! \return The number of occurrences of the character in the text
  429. DLLEXPORT int anzahlVon(char c) const;
  430. //! Counts how often a specific string occurs in the text
  431. //! \param t The string to be counted
  432. //! \return The number of occurrences of the string in the text
  433. DLLEXPORT int anzahlVon(const char* t) const;
  434. //! Counts how often a specific string occurs in the text
  435. //! \param t The string to be counted
  436. //! \param len The length of the string to be counted
  437. //! \return The number of occurrences of the string in the text
  438. DLLEXPORT int anzahlVon(const char* t, int len) const;
  439. //! Counts how often the content of a Text occurs in the text
  440. //! \param t The Text whose content should be counted
  441. //! \return The number of occurrences of the text content
  442. DLLEXPORT int anzahlVon(const Text& t) const;
  443. //! Returns the first position of a specific character in the text
  444. //! \param c The character to be found
  445. //! \return The position of the first occurrence of the character
  446. DLLEXPORT int positionVon(char c) const;
  447. //! Returns the first position of a specific string in the text
  448. //! \param t The string to be found
  449. //! \return The position of the first occurrence of the string
  450. DLLEXPORT int positionVon(const char* t) const;
  451. //! Returns the first position of a specific string in the text
  452. //! \param len The length of the string to be found
  453. //! \param t The string to be found
  454. //! \return The position of the first occurrence of the string
  455. DLLEXPORT int positionVon(int len, const char* t) const;
  456. //! Returns the first position of a specific string in the text
  457. //! \param searchStart Index from which to start searching
  458. //! \param t The string to be found
  459. //! \return The position of the first occurrence of the string
  460. DLLEXPORT int positionVon(
  461. int searchStart, const char* t, int len) const;
  462. //! Returns the first position of a Text's content in the text
  463. //! \param t The Text whose content should be found
  464. //! \return The position of the first occurrence of the text content
  465. DLLEXPORT int positionVon(const Text& t) const;
  466. //! Returns the i-th position of a specific character in the text
  467. //! \param c The character to be found
  468. //! \param i Which occurrence should be found
  469. //! \return The position of the i-th occurrence of the character
  470. DLLEXPORT int positionVon(char c, int i) const;
  471. //! Returns the i-th position of a specific string in the text
  472. //! \param t The string to be found
  473. //! \param i Which occurrence should be found
  474. //! \return The position of the i-th occurrence of the string
  475. DLLEXPORT int positionVon(const char* t, int i) const;
  476. //! Returns the i-th position of a specific string in the text
  477. //! \param t The string to be found
  478. //! \param len The length of the string to be found
  479. //! \param i Which occurrence should be found
  480. //! \return The position of the i-th occurrence of the string
  481. DLLEXPORT int positionVon(int i, int len, const char* t) const;
  482. //! Returns the i-th position of a Text's content in the text
  483. //! \param t The Text whose content should be found
  484. //! \param i Which occurrence should be found
  485. //! \return The position of the i-th occurrence of the text content
  486. DLLEXPORT int positionVon(const Text& t, int i) const;
  487. //! Returns a Text containing a copy of a specific text section
  488. //! p1: The start position of the text section
  489. //! p2: The end position of the text section (not included)
  490. DLLEXPORT Text* getTeilText(int p1, int p2) const;
  491. //! Returns a Text containing a copy of a specific text section
  492. //! p1: The start position of the text section (the section extends to
  493. //! the end of the text)
  494. DLLEXPORT Text* getTeilText(int p) const;
  495. //! Computes the hash code of the text
  496. DLLEXPORT int hashCode() const;
  497. //! Appends a number to the end of the text
  498. DLLEXPORT Text& operator+=(const int num);
  499. //! Appends a number to the end of the text
  500. DLLEXPORT Text& operator+=(const __int64 num);
  501. //! Appends a floating-point number to the end of the text
  502. DLLEXPORT Text& operator+=(const double num);
  503. //! Appends a floating-point number to the end of the text
  504. DLLEXPORT Text& operator+=(const float num);
  505. //! Appends a string to the end of the text
  506. DLLEXPORT Text& operator+=(const char* txt);
  507. //! Appends a copy of the content of a Text to the end of the text
  508. DLLEXPORT Text& operator+=(const Text& txt);
  509. //! Sets the content of the text equal to a number
  510. DLLEXPORT Text& operator=(const int num);
  511. //! Sets the content of the text equal to a floating-point number
  512. DLLEXPORT Text& operator=(const double num);
  513. //! Sets the content of the text equal to a floating-point number
  514. DLLEXPORT Text& operator=(const float num);
  515. //! Sets the content of the text equal to a string
  516. DLLEXPORT Text& operator=(const char* txt);
  517. //! Sets the content of the text equal to a copy of another Text's
  518. //! content
  519. DLLEXPORT Text& operator=(const Text& txt);
  520. //! Returns the content of the text as a string
  521. DLLEXPORT operator const char*() const;
  522. //! Converts the content of the text to a number
  523. DLLEXPORT explicit operator int() const;
  524. //! Converts the content of the text to a number
  525. DLLEXPORT explicit operator __int64() const;
  526. //! Converts the content of the text to a floating-point number
  527. DLLEXPORT explicit operator double() const;
  528. //! Converts the content of the text to a floating-point number
  529. DLLEXPORT explicit operator float() const;
  530. //! Checks whether the content of the text comes later in alphabetical
  531. //! order than the content of another text
  532. DLLEXPORT bool operator>(Text& t) const;
  533. //! Checks whether the content of the text comes earlier in alphabetical
  534. //! order than the content of another text
  535. DLLEXPORT bool operator<(Text& t) const;
  536. //! Creates a new Text consisting of this text and t2
  537. DLLEXPORT Text operator+(const Text& t2) const;
  538. //! Creates a new Text consisting of this text and t2
  539. DLLEXPORT Text operator+(const char* t2) const;
  540. //! Creates a new Text consisting of this text and num
  541. DLLEXPORT Text operator+(const int num) const;
  542. //! Creates a new Text consisting of this text and num
  543. DLLEXPORT Text operator+(const __int64 num) const;
  544. //! Creates a new Text consisting of this text and num
  545. DLLEXPORT Text operator+(const double num) const;
  546. //! Creates a new Text consisting of this text and num
  547. DLLEXPORT Text operator+(const float num) const;
  548. //! Checks whether the text matches another text
  549. DLLEXPORT bool operator==(const Text& right) const;
  550. //! creates a Text from a char array. the array will be deleted when the
  551. //! destructor of Text is called
  552. DLLEXPORT static Text fromArray(char* arr, int len);
  553. static const Text EMPTY;
  554. };
  555. class TextReader : public Reader,
  556. public virtual ReferenceCounter
  557. {
  558. private:
  559. Text* txt;
  560. __int64 lPos;
  561. public:
  562. //! Constructor
  563. //! \param txt The text to be read. It is not copied but read directly.
  564. DLLEXPORT TextReader(Text* txt);
  565. //! Destructor
  566. DLLEXPORT virtual ~TextReader();
  567. //! Sets the position of the byte to be read next
  568. //! \param pos The index of the byte
  569. //! \param ende 1 if the index counts from the end of the text. 0 if the
  570. //! index counts from the beginning of the text
  571. DLLEXPORT void setLPosition(__int64 pos, bool ende) override;
  572. //! Reads from the text
  573. //! \param bytes An array to be filled with bytes from the text
  574. //! \param len How many bytes should be read from the text
  575. DLLEXPORT void lese(char* bytes, int len) override;
  576. //! Reads the next line of the text
  577. //! \return The read line as Text with line break
  578. DLLEXPORT Text* leseZeile() override;
  579. //! Checks whether the resource has been fully read
  580. //! return 1 if the resource has been fully read. 0 otherwise
  581. DLLEXPORT bool istEnde() const override;
  582. //! Returns the index of the byte from the text that would be read next
  583. //! return -1 if an error occurred. Otherwise the position of the read
  584. //! pointer
  585. DLLEXPORT __int64 getLPosition() const override;
  586. //! Returns the number of bytes to be read
  587. DLLEXPORT __int64 getSize() const override;
  588. };
  589. //! Searches a string for the num-th occurrence of a specific character
  590. //! \param string The string to be searched
  591. //! \param c The character to search for
  592. //! \param num Which occurrence of the character should be found
  593. //! \return (-1) if there is no num-th occurrence of the character.
  594. //! Otherwise the position of the num-th occurrence in the string
  595. DLLEXPORT int stringPositionVonChar(const char* string,
  596. char c,
  597. int num); //! searches the position of the num-th c in string, -1 if not
  598. //! found
  599. //! Searches a string for another string
  600. //! \param string The string to be searched
  601. //! \param suche The string to search for
  602. //! \param sBegPos The position from which to start the search
  603. //! \return The position where the search string was first found.
  604. //! (-1) if nothing was found.
  605. DLLEXPORT int stringPositionVonString(
  606. const char* string, char* suche, int sBegPos);
  607. //! Copies a specific string to the operating system's clipboard
  608. //! \param txt The string to be copied
  609. DLLEXPORT void TextKopieren(const char* txt);
  610. //! Determines whether a string is stored in the operating system's
  611. //! clipboard.
  612. //! \return The string from the clipboard. If no string was copied, an empty
  613. //! string is returned.
  614. DLLEXPORT const char* TextInsert();
  615. //! Converts a specific writable character to uppercase or lowercase
  616. //! \param c The character to be converted
  617. //! \param big If (true), the character is converted to uppercase.
  618. //! If (false), it is converted to lowercase.
  619. //! \return The converted character
  620. DLLEXPORT char smallOrBig(char c, bool big);
  621. //! Determines whether a character is a printable character
  622. //! \param zeichen The character to be checked
  623. //! \return (true) if the character can be drawn. (false) otherwise
  624. DLLEXPORT bool istSchreibbar(unsigned char zeichen);
  625. //! Converts a number from a string in any base to a number
  626. //! \param c The string containing the number
  627. //! \param system The base of the number
  628. //! \return The number that was in the text
  629. DLLEXPORT unsigned int TextZuInt(const char* c, int system);
  630. //! Converts a number from a string in any base to a number
  631. //! \param c The string containing the number
  632. //! c_ende: Set by the function and may be 0. Points to the next character
  633. //! in the string after the number
  634. //! \param system The base of the number
  635. //! \return The number that was in the text
  636. DLLEXPORT unsigned int TextZuInt(const char* c, char** c_ende, int system);
  637. //! Converts a number from a string in any base to a number
  638. //! \param c The string containing the number
  639. //! \param system The base of the number
  640. //! \return The number that was in the text
  641. DLLEXPORT unsigned __int64 TextZuInt64(const char* c, int system);
  642. //! Converts a number from a string in any base to a number
  643. //! \param c The string containing the number
  644. //! c_ende: Set by the function and may be 0. Points to the next character
  645. //! in the string after the number
  646. //! \param system The base of the number
  647. //! \return The number that was in the text
  648. DLLEXPORT unsigned __int64 TextZuInt64(
  649. const char* c, char** c_ende, int system);
  650. //! Converts a string to a double
  651. //! \param c The string to be converted
  652. //! \return The double that was in the string
  653. DLLEXPORT double TextZuDouble(const char* c);
  654. //! Converts a string to a float
  655. //! \param c The string to be converted
  656. //! \return The float that was in the string
  657. DLLEXPORT float TextZuFloat(const char* c);
  658. //! Converts a string to a double
  659. //! \param c The string to be converted
  660. //! c_ende: Set by the function and may be 0. A pointer to the next
  661. //! character after the double in the string
  662. //! \return The double that was in the string
  663. DLLEXPORT double TextZuDouble(const char* c, char** c_ende);
  664. //! Converts a string to a float
  665. //! \param c The string to be converted
  666. //! c_ende: Set by the function and may be 0. A pointer to the next
  667. //! character after the float in the string
  668. //! \return The float that was in the string
  669. DLLEXPORT float TextZuFloat(const char* c, char** c_ende);
  670. //! Determines the length of a specific string
  671. //! \param txt The string whose length should be determined
  672. //! \return The length of the string
  673. DLLEXPORT int textLength(const char* txt);
  674. } // namespace Framework