Text.h 35 KB

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