EATextUtil.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
  2. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  3. <Title>EATextUtil</title>
  4. <link type="text/css" rel="stylesheet" href="UTFDoc.css">
  5. <meta name="author" content="Paul Pedriana">
  6. </head>
  7. <body bgcolor="#FFFFFF">
  8. <h1>EATextUtil</h1>
  9. <h2>Introduction</h2>
  10. <p>EATextUtil is a collection of string utilities that are of a higher-level nature than those found in the C runtime library or our <a href="EAString.html">EAString</a>
  11. module. EASTL/string.h and EASTL/algorithm.h contain C++/STL variations of functions that are similar to the C runtime library functions, but which are generally
  12. more powerful and flexible than the C functions while usually being more efficient. </p>
  13. <p>All functions in EATextUtil are present in char8_t versions and char16_t versions, and assume UTF8 and UCS2 Unicode encoding respectively. Recall that these encodings
  14. are backward-compatible with ASCII and so will work for most or all of the text that you give them. </p>
  15. <p>Each of the functions comes in a version that doesn't allocate any memory but instead uses user-supplied memory in-place. In a few cases, there are String versions
  16. that will allocate memory if they need to increase the size of the user-supplied string.</p>
  17. <p>Here's a brief summary of the functions currently found in EATextUtil. We use char_t in the declarations below to refer to both char8_t and char16_t; there are
  18. thus two versions of each function. </p>
  19. <pre class="code-example">bool WildcardMatch(const char_t* pString, const char_t* pPattern, bool bCaseSensitive);
  20. bool ParseDelimitedText(const char_t* pText, const char_t* pTextEnd, char_t cDelimiter,
  21. const char_t*& pToken, const char_t*& pTokenEnd, const char_t** ppNewText);
  22. const char_t* GetTextLine(const char_t* pText, const char_t* pTextEnd, const char_t** ppNewText);
  23. bool SplitTokenDelimited(const char_t* pSource, size_t nSourceLength, char_t cDelimiter,
  24. char_t* pToken, size_t nTokenLength, const char_t** ppNewSource = NULL);
  25. bool SplitTokenSeparated(const char_t* pSource, size_t nSourceLength, char_t cDelimiter,
  26. char_t* pToken, size_t nTokenLength, const char_t** ppNewSource = NULL);
  27. void ConvertBinaryDataToASCIIArray(const void* pBinaryData, size_t nBinaryDataLength, char_t* pASCIIArray);
  28. bool ConvertASCIIArrayToBinaryData(const char_t* pASCIIArray, size_t nASCIIArrayLength, void* pBinaryData);
  29. int BoyerMooreSearch(const char8_t* pPattern, int nPatternLength, const char8_t* pSearchString, int nSearchStringLength,
  30. int* pPatternBuffer1, int* pPatternBuffer2, int* pAlphabetBuffer, int nAlphabetBufferSize);
  31. </pre>
  32. <p>We will proceed to address each of the above functions.</p>
  33. <h2>WildcardMatch</h2>
  34. <pre class="code-example">bool WildcardMatch(const char16_t* pString, const char16_t* pPattern, bool bCaseSensitive);
  35. bool WildcardMatch(const char8_t* pString, const char8_t* pPattern, bool bCaseSensitive);
  36. </pre>
  37. <p>These functions match source strings to wildcard patterns like those used in file specifications. '*' in the pattern means match zero or more consecutive source
  38. characters. '?' in the pattern means match exactly one source character. Multiple * and ? characters may be used. Two consecutive * characters are treated as
  39. if they were one. Here are some examples:</p>
  40. <table width="500" border="1" hspace="32">
  41. <tr>
  42. <td><b>Source</b></td>
  43. <td><b>Pattern</b></td>
  44. <td><b>Result</b></td>
  45. </tr>
  46. <tr>
  47. <td>abcde</td>
  48. <td>*e</td>
  49. <td>true</td>
  50. </tr>
  51. <tr>
  52. <td>abcde</td>
  53. <td>*f</td>
  54. <td>false</td>
  55. </tr>
  56. <tr>
  57. <td>abcde</td>
  58. <td>???de</td>
  59. <td>true</td>
  60. </tr>
  61. <tr>
  62. <td>abcde</td>
  63. <td>????g</td>
  64. <td>false</td>
  65. </tr>
  66. <tr>
  67. <td>abcde</td>
  68. <td>*c??</td>
  69. <td>true</td>
  70. </tr>
  71. <tr>
  72. <td>abcde</td>
  73. <td>*e??</td>
  74. <td>false</td>
  75. </tr>
  76. <tr>
  77. <td>abcde</td>
  78. <td>*????</td>
  79. <td>true</td>
  80. </tr>
  81. <tr>
  82. <td>abcde</td>
  83. <td>bcdef</td>
  84. <td>false</td>
  85. </tr>
  86. <tr>
  87. <td>abcde</td>
  88. <td> *?????</td>
  89. <td>true</td>
  90. </tr>
  91. </table>
  92. <p>Example usage:</p>
  93. <pre class="code-example">bool result = WildcardMatch(&quot;Hello world&quot;, &quot;hello*&quot;, false); <font color="#0033CC"> // result becomes true</font>
  94. bool result = WildcardMatch(&quot;Hello world&quot;, &quot;hello?&quot;, false); <font color="#0033CC">// result becomes false</font>
  95. bool result = WildcardMatch(&quot;Hello world&quot;, &quot;Hello??orld&quot;, true); <font color="#0033CC">// result becomes true</font>
  96. bool result = WildcardMatch(&quot;Hello world&quot;, &quot;*Hello*world*&quot;, true); <font color="#0033CC">// result becomes true</font>
  97. </pre>
  98. <h2>ParseDelimitedText (iterative version)</h2>
  99. <pre class="code-example">bool ParseDelimitedText(const char16_t* pText, const char16_t* pTextEnd, char16_t cDelimiter,
  100. const char16_t*& pToken, const char16_t*& pTokenEnd, const char16_t** ppNewText);
  101. bool ParseDelimitedText(const char8_t* pText, const char8_t* pTextEnd, char8_t cDelimiter,
  102. const char8_t*& pToken, const char8_t*& pTokenEnd, const char8_t** ppNewText);
  103. </pre>
  104. <p>Given a line of text (e.g. like this:)</p>
  105. <pre class="code-example">342.5, &quot;This is a string&quot;, test, &quot;This is a string, with a comma&quot;</pre>
  106. <p>ParseDelimitedText parses it into separate fields (e.g. like this:)</p>
  107. <pre class="code-example">342.5
  108. This is a string
  109. test
  110. This is a string, with a comma </pre>
  111. <p> ParseDelimitedText lets you dynamically specify the delimiter. The delimiter can be any char (e.g. space, tab, semicolon) except the quote char itself, which
  112. is reserved for the purpose of grouping. See the source code comments for more details. However, in the case of text that is UTF8-encoded, you need to make sure
  113. the delimiter char is a value that is less than 127, so as not to collide with UTF8 encoded chars.<br>
  114. <br>
  115. The input is a pointer to text and the text length. For ASCII, MBCS, and UTF8, this is the number of bytes or chars. For UTF16 (Unicode) it is the number of characters.
  116. There are two bytes (two chars) per character in UTF16. The input nTextLength can be -1 (kLengthNull) to indicate that the string is null-terminated. </p>
  117. <p>Example behaviour for string array version (which you can extrapolate to the iterative version):</p>
  118. <table width="100%" border="1">
  119. <tr>
  120. <td><b>Input string</b></td>
  121. <td><b>MaxResults</b></td>
  122. <td><b>Delimiter</b></td>
  123. <td><b>Return value</b></td>
  124. <td>
  125. <p><b>O</b><b>utput array size</b></p>
  126. </td>
  127. <td><b>Output array value</b></td>
  128. </tr>
  129. <tr>
  130. <td>
  131. <pre><font size="-1">""</font></pre>
  132. </td>
  133. <td><font size="-1">-1</font></td>
  134. <td>
  135. <pre><font size="-1">' '</font></pre>
  136. </td>
  137. <td><font size="-1">0</font></td>
  138. <td><font size="-1">0</font></td>
  139. <td>
  140. <pre><font size="-1">""</font></pre>
  141. </td>
  142. </tr>
  143. <tr>
  144. <td>
  145. <pre><font size="-1">"000 111"</font></pre>
  146. </td>
  147. <td><font size="-1">-1</font></td>
  148. <td>
  149. <pre><font size="-1">' '</font></pre>
  150. </td>
  151. <td><font size="-1">2</font></td>
  152. <td><font size="-1">2</font></td>
  153. <td>
  154. <pre><font size="-1">"000" "111"</font></pre>
  155. </td>
  156. </tr>
  157. <tr>
  158. <td>
  159. <pre><font size="-1">"000 111 222 333 444 \"555 555\" 666"</font></pre>
  160. </td>
  161. <td><font size="-1">-1</font></td>
  162. <td>
  163. <pre><font size="-1">' '</font></pre>
  164. </td>
  165. <td><font size="-1">7</font></td>
  166. <td><font size="-1">7</font></td>
  167. <td>
  168. <pre><font size="-1">"000" "111" "222" "333" "444" "555 555" "666"</font></pre>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td>
  173. <pre><font size="-1">" 000 111 222 333 "</font></pre>
  174. </td>
  175. <td><font size="-1">-1</font></td>
  176. <td>
  177. <pre><font size="-1">' '</font></pre>
  178. </td>
  179. <td><font size="-1">4</font></td>
  180. <td><font size="-1">4</font></td>
  181. <td>
  182. <pre><font size="-1">"000" "111" "222" "333"</font></pre>
  183. </td>
  184. </tr>
  185. <tr>
  186. <td>
  187. <pre><font size="-1">" 000 111 222 333 "</font></pre>
  188. </td>
  189. <td><font size="-1">-1</font></td>
  190. <td>
  191. <pre><font size="-1">' '</font></pre>
  192. </td>
  193. <td><font size="-1">2</font></td>
  194. <td><font size="-1">2</font></td>
  195. <td>
  196. <pre><font size="-1">"000" "111"</font></pre>
  197. </td>
  198. </tr>
  199. <tr>
  200. <td>
  201. <pre><font size="-1">""</font></pre>
  202. </td>
  203. <td><font size="-1">-1</font></td>
  204. <td>
  205. <pre><font size="-1">','</font></pre>
  206. </td>
  207. <td><font size="-1">0</font></td>
  208. <td><font size="-1">0</font></td>
  209. <td>
  210. <pre><font size="-1">""</font></pre>
  211. </td>
  212. </tr>
  213. <tr>
  214. <td>
  215. <pre><font size="-1">"000,111"</font></pre>
  216. </td>
  217. <td><font size="-1">-1</font></td>
  218. <td>
  219. <pre><font size="-1">','</font></pre>
  220. </td>
  221. <td><font size="-1">2</font></td>
  222. <td><font size="-1">2</font></td>
  223. <td>
  224. <pre><font size="-1">"000" "111"</font></pre>
  225. </td>
  226. </tr>
  227. <tr>
  228. <td>
  229. <pre><font size="-1">"000, 111 , 222 333 ,444 \"555, 555 \" 666"</font></pre>
  230. </td>
  231. <td><font size="-1">-1</font></td>
  232. <td>
  233. <pre><font size="-1">','</font></pre>
  234. </td>
  235. <td><font size="-1">4</font></td>
  236. <td><font size="-1">4</font></td>
  237. <td>
  238. <pre><font size="-1">"000" "111" "222 333" "444 \"555, 555 \" 666"</font></pre>
  239. </td>
  240. </tr>
  241. <tr>
  242. <td>
  243. <pre><font size="-1">" ,, 000 ,111, 222, 333 , "</font></pre>
  244. </td>
  245. <td><font size="-1">-1</font></td>
  246. <td>
  247. <pre><font size="-1">','</font></pre>
  248. </td>
  249. <td><font size="-1">6</font></td>
  250. <td><font size="-1">6</font></td>
  251. <td>
  252. <pre><font size="-1">"" "" "000" "111" "222" "333"</font></pre>
  253. </td>
  254. </tr>
  255. <tr>
  256. <td>
  257. <pre><font size="-1">" ,, 000 ,111, 222, 333 , "</font></pre>
  258. </td>
  259. <td><font size="-1">2 </font></td>
  260. <td>
  261. <pre><font size="-1">','</font></pre>
  262. </td>
  263. <td><font size="-1">0</font></td>
  264. <td><font size="-1">0</font></td>
  265. <td>
  266. <pre><font size="-1">"" ""</font></pre>
  267. </td>
  268. </tr>
  269. </table>
  270. <h2>Convert binary ASCII</h2>
  271. <pre class="code-example">void ConvertBinaryDataToASCIIArray(const void* pBinaryData, size_t nBinaryDataLength, char16_t* pASCIIArray);
  272. void ConvertBinaryDataToASCIIArray(const void* pBinaryData, size_t nBinaryDataLength, char8_t* pASCIIArray);
  273. bool ConvertASCIIArrayToBinaryData(const char8_t* pASCIIArray, size_t nASCIIArrayLength, void* pBinaryData);
  274. bool ConvertASCIIArrayToBinaryData(const char16_t* pASCIIArray, size_t nASCIIArrayLength, void* pBinaryData);
  275. </pre>
  276. <p> The first two functions convert an array of binary characters into an encoded ASCII format that can be later converted back to binary. You might want to do this
  277. if you are trying to embed binary data into a text file (e.g. .ini file) and need a way to encode the binary data as text.</p>
  278. <p> The second two functions take an ASCII string of text and converts it to binary data. This is the reverse of the ConvertBinaryDataToASCIIArray functions. If an
  279. invalid hexidecimal character is encountered, it is replaced with a '0' character. These functions return true if the input was entirely valid hexadecimal data.</p>
  280. <p>Example usage:</p>
  281. <pre class="code-example">const uint8_t data[4] = { 0x12, 0x34, 0x56, 0x78 };
  282. char8_t ascii[8];
  283. ConvertBinaryDataToASCIIArray(data, 4 * sizeof(uint8_t), ascii); <font color="#0033CC">// ascii becomes "12345678"</font>
  284. </pre>
  285. <pre class="code-example">const char16_t ascii[8] = &quot;12345678&quot;;
  286. uint8_t data[4];
  287. ConvertASCIIArrayToBinaryData(ascii, 8, data); <font color="#0033CC">// data becomes { 0x12, 0x34, 0x56, 0x78 }</font>
  288. </pre>
  289. <h2>GetTextLine</h2>
  290. <pre class="code-example">const char16_t* GetTextLine(const char16_t* pText, const char16_t* pTextEnd, const char16_t** ppNewText);
  291. const char8_t* GetTextLine(const char8_t* pText, const char8_t* pTextEnd, const char8_t** ppNewText);
  292. </pre>
  293. <p>Given a block of text, this function reads a line of text and moves to the beginning of the next line. The return value is the end of the current line, previous
  294. to the newline characters. If ppNewText is supplied, it holds the start of the new line, which will often be different from the return value, as the start of
  295. the new line is after any newline characters. The length of the current line is pTextEnd - pText.</p>
  296. <p>These functions are useful for reading lines of text from a text file via an iterative method, which is perhaps the most flexible way of doing this.</p>
  297. <p>Example usage:</p>
  298. <pre class="code-example">char buffer[256];<br>char* pLineNext(buffer);<br>char* pLine;<br><br>do{<br> pText = pLineNext;<br> const char* pLineEnd = GetTextLine(pLine, buffer + 256, &amp;pLineNext);<br> <span class="code-example-comment">// Use pLine - pLineEnd here</span><br>}while(pLineNext != (buffer + 256));</pre>
  299. <h2>SplitTokenDelimited </h2>
  300. <pre class="code-example">bool SplitTokenDelimited(const char16_t* pSource, size_t nSourceLength, char16_t cDelimiter,
  301. char16_t* pToken, size_t nTokenLength, const char16_t** ppNewSource = NULL);
  302. bool SplitTokenDelimited(const char8_t* pSource, size_t nSourceLength, char8_t cDelimiter,
  303. char8_t* pToken, size_t nTokenLength, const char8_t** ppNewSource = NULL);
  304. </pre>
  305. <p> SplitTokenDelimited returns tokens that are delimited by a single character -- repetitions of that character will result in empty tokens returned. This is most
  306. commonly useful when you want to parse a string of text delimited by commas or spaces. Returns true whenever it extracts a token. Note however that the extracted
  307. token may be empty. Note that the return value will be true if the source has length and will be false if the source is empty. If the input pToken is non-null,
  308. the text before the delimiter is copied to it. </p>
  309. <p>Example behaviour (delimiter is a comma):</p>
  310. <table width="500" border="1" hspace="32">
  311. <tr>
  312. <td><b>Source</b></td>
  313. <td><b>Token</b></td>
  314. <td><b>New source</b></td>
  315. <td><b>Return value</b></td>
  316. </tr>
  317. <tr>
  318. <td>
  319. <pre>"a,b"</pre>
  320. </td>
  321. <td>
  322. <pre>"a"</pre>
  323. </td>
  324. <td>
  325. <pre>"b"</pre>
  326. </td>
  327. <td>
  328. <pre>true</pre>
  329. </td>
  330. </tr>
  331. <tr>
  332. <td>
  333. <pre>" a , b "</pre>
  334. </td>
  335. <td>
  336. <pre>" a "</pre>
  337. </td>
  338. <td>
  339. <pre>" b "</pre>
  340. </td>
  341. <td>
  342. <pre>true</pre>
  343. </td>
  344. </tr>
  345. <tr>
  346. <td>
  347. <pre>"ab,b"</pre>
  348. </td>
  349. <td>
  350. <pre>"ab"</pre>
  351. </td>
  352. <td>
  353. <pre>"b"</pre>
  354. </td>
  355. <td>
  356. <pre>true</pre>
  357. </td>
  358. </tr>
  359. <tr>
  360. <td>
  361. <pre>",a,b"</pre>
  362. </td>
  363. <td>
  364. <pre>""</pre>
  365. </td>
  366. <td>
  367. <pre>"a,b"</pre>
  368. </td>
  369. <td>
  370. <pre>true</pre>
  371. </td>
  372. </tr>
  373. <tr>
  374. <td>
  375. <pre>",b"</pre>
  376. </td>
  377. <td>
  378. <pre>""</pre>
  379. </td>
  380. <td>
  381. <pre>"b"</pre>
  382. </td>
  383. <td>
  384. <pre>true</pre>
  385. </td>
  386. </tr>
  387. <tr>
  388. <td>
  389. <pre>",,b"</pre>
  390. </td>
  391. <td>
  392. <pre>""</pre>
  393. </td>
  394. <td>
  395. <pre>",b"</pre>
  396. </td>
  397. <td>
  398. <pre>true</pre>
  399. </td>
  400. </tr>
  401. <tr>
  402. <td>
  403. <pre>",a,"</pre>
  404. </td>
  405. <td>
  406. <pre>""</pre>
  407. </td>
  408. <td>
  409. <pre>"a,"</pre>
  410. </td>
  411. <td>
  412. <pre>true</pre>
  413. </td>
  414. </tr>
  415. <tr>
  416. <td>
  417. <pre>"a,"</pre>
  418. </td>
  419. <td>
  420. <pre>"a"</pre>
  421. </td>
  422. <td>
  423. <pre>""</pre>
  424. </td>
  425. <td>
  426. <pre>true</pre>
  427. </td>
  428. </tr>
  429. <tr>
  430. <td>
  431. <pre>","</pre>
  432. </td>
  433. <td>
  434. <pre>""</pre>
  435. </td>
  436. <td>
  437. <pre>""</pre>
  438. </td>
  439. <td>
  440. <pre>true</pre>
  441. </td>
  442. </tr>
  443. <tr>
  444. <td>
  445. <pre>", "</pre>
  446. </td>
  447. <td>
  448. <pre>""</pre>
  449. </td>
  450. <td>
  451. <pre>&quot; &quot;</pre>
  452. </td>
  453. <td>
  454. <pre>true</pre>
  455. </td>
  456. </tr>
  457. <tr>
  458. <td>
  459. <pre>"a"</pre>
  460. </td>
  461. <td>
  462. <pre>"a"</pre>
  463. </td>
  464. <td>
  465. <pre>""</pre>
  466. </td>
  467. <td>
  468. <pre>true</pre>
  469. </td>
  470. </tr>
  471. <tr>
  472. <td>
  473. <pre>" "</pre>
  474. </td>
  475. <td>
  476. <pre>&quot; &quot;</pre>
  477. </td>
  478. <td>
  479. <pre>""</pre>
  480. </td>
  481. <td>
  482. <pre>true</pre>
  483. </td>
  484. </tr>
  485. <tr>
  486. <td>
  487. <pre>""</pre>
  488. </td>
  489. <td>
  490. <pre>&quot;&quot;</pre>
  491. </td>
  492. <td>
  493. <pre>""</pre>
  494. </td>
  495. <td>
  496. <pre>false</pre>
  497. </td>
  498. </tr>
  499. <tr>
  500. <td>
  501. <pre>NULL</pre>
  502. </td>
  503. <td>
  504. <pre>&quot;&quot;</pre>
  505. </td>
  506. <td>
  507. <pre>NULL</pre>
  508. </td>
  509. <td>
  510. <pre>false</pre>
  511. </td>
  512. </tr>
  513. </table>
  514. <p>Example usage:</p>
  515. <pre class="code-example">const char16_t* pString = L"a, b, c, d";
  516. char16_t pToken[16];
  517. while(SplitTokenDelimited(pString, kLengthNull, ',', pToken, 16, &pString))
  518. printf("%s\n", pToken);
  519. </pre>
  520. <h2>SplitTokenSeparated </h2>
  521. <pre class="code-example">bool SplitTokenSeparated(const char16_t* pSource, size_t nSourceLength, char16_t cDelimiter,
  522. char16_t* pToken, size_t nTokenLength, const char16_t** ppNewSource = NULL);
  523. bool SplitTokenSeparated(const char8_t* pSource, size_t nSourceLength, char8_t cDelimiter,
  524. char8_t* pToken, size_t nTokenLength, const char8_t** ppNewSource = NULL);</pre>
  525. <p>SplitTokenSeparated returns tokens that are separated by one or more instances of a character. Returns true whenever it extracts a token. </p>
  526. <p>Example behaviour (delimiter is a space char):</p>
  527. <table width="500" border="1" hspace="32">
  528. <tr>
  529. <td><b>Source</b></td>
  530. <td><b>Token</b></td>
  531. <td><b>New source</b></td>
  532. <td><b>Return value</b></td>
  533. </tr>
  534. <tr>
  535. <td>
  536. <pre>"a"</pre>
  537. </td>
  538. <td>
  539. <pre>"a"</pre>
  540. </td>
  541. <td>
  542. <pre>""</pre>
  543. </td>
  544. <td>
  545. <pre>true</pre>
  546. </td>
  547. </tr>
  548. <tr>
  549. <td>
  550. <pre>"a b"</pre>
  551. </td>
  552. <td>
  553. <pre>"a"</pre>
  554. </td>
  555. <td>
  556. <pre>"b"</pre>
  557. </td>
  558. <td>
  559. <pre>true</pre>
  560. </td>
  561. </tr>
  562. <tr>
  563. <td>
  564. <pre>"a b"</pre>
  565. </td>
  566. <td>
  567. <pre>"a"</pre>
  568. </td>
  569. <td>
  570. <pre>"b"</pre>
  571. </td>
  572. <td>
  573. <pre>true</pre>
  574. </td>
  575. </tr>
  576. <tr>
  577. <td>
  578. <pre>" a b"</pre>
  579. </td>
  580. <td>
  581. <pre>"a"</pre>
  582. </td>
  583. <td>
  584. <pre>"b"</pre>
  585. </td>
  586. <td>
  587. <pre>true</pre>
  588. </td>
  589. </tr>
  590. <tr>
  591. <td>
  592. <pre>" a b "</pre>
  593. </td>
  594. <td>
  595. <pre>"a"</pre>
  596. </td>
  597. <td>
  598. <pre>"b "</pre>
  599. </td>
  600. <td>
  601. <pre>true</pre>
  602. </td>
  603. </tr>
  604. <tr>
  605. <td>
  606. <pre>" a "</pre>
  607. </td>
  608. <td>
  609. <pre>"a"</pre>
  610. </td>
  611. <td>
  612. <pre>""</pre>
  613. </td>
  614. <td>
  615. <pre>true</pre>
  616. </td>
  617. </tr>
  618. <tr>
  619. <td>
  620. <pre>" a "</pre>
  621. </td>
  622. <td>
  623. <pre>"a"</pre>
  624. </td>
  625. <td>
  626. <pre>""</pre>
  627. </td>
  628. <td>
  629. <pre>true</pre>
  630. </td>
  631. </tr>
  632. <tr>
  633. <td>
  634. <pre>""</pre>
  635. </td>
  636. <td>
  637. <pre>&quot;&quot;</pre>
  638. </td>
  639. <td>
  640. <pre>""</pre>
  641. </td>
  642. <td>
  643. <pre>false</pre>
  644. </td>
  645. </tr>
  646. <tr>
  647. <td>
  648. <pre>" "</pre>
  649. </td>
  650. <td>
  651. <pre>&quot;&quot;</pre>
  652. </td>
  653. <td>
  654. <pre>""</pre>
  655. </td>
  656. <td>
  657. <pre>false</pre>
  658. </td>
  659. </tr>
  660. <tr>
  661. <td>
  662. <pre>NULL</pre>
  663. </td>
  664. <td>
  665. <pre>&quot;&quot;</pre>
  666. </td>
  667. <td>
  668. <pre>NULL</pre>
  669. </td>
  670. <td>
  671. <pre>false</pre>
  672. </td>
  673. </tr>
  674. </table>
  675. <h2>BoyerMooreSearch</h2>
  676. <pre class="code-example"><span class="code-example-comment">/// BoyerMooreSearch
  677. ///
  678. /// patternBuffer1 is a user-supplied buffer and must be at least as long as the search pattern.
  679. /// patternBuffer2 is a user-supplied buffer and must be at least as long as the search pattern.
  680. /// alphabetBuffer is a user-supplied buffer and must be at least as long as the highest character value
  681. /// used in the searched string and search pattern.
  682. ///
  683. </span>int BoyerMooreSearch(const char* pPattern, int nPatternLength, const char* pSearchString, int nSearchStringLength,
  684. int* pPatternBuffer1, int* pPatternBuffer2, int* pAlphabetBuffer, int nAlphabetBufferSize)
  685. </pre>
  686. <p> Boyer-Moore is a very fast string search compared to most others, including those in the STL. However, you need to be searching a string of at least 100 chars
  687. and have a search pattern of at least 3 characters for the speed to show, as Boyer-Moore has a startup precalculation that costs some cycles. This startup precalculation
  688. is proportional to the size of your search pattern and the size of the alphabet in use. Thus, doing Boyer-Moore searches on the entire Unicode alphabet is going
  689. to incur a fairly expensive precalculation cost.</p>
  690. <hr>
  691. <p>&nbsp;</p>
  692. <p>&nbsp;</p>
  693. <p>&nbsp;</p>
  694. <p>&nbsp;</p>
  695. <p>&nbsp;</p>
  696. <p>&nbsp;</p>
  697. <p>&nbsp;</p>
  698. <p>&nbsp;</p>
  699. <p>&nbsp;</p>
  700. <p>&nbsp;</p>
  701. <p>&nbsp;</p>
  702. <p>&nbsp;</p>
  703. <p>&nbsp;</p>
  704. <p> </p>
  705. </body></html>