Search for a character. Search for the position of the needle in the haystack. Default mode is StrCase | StrLeft, mode also accepts StrNoCase and StrRight. If pos is non-zero, then in mode StrLeft the search starts at (hay + pos) and in mode StrRight the search starts at (hay + pos - 1) @return Returns a pointer to the location of the character in the haystack or 0
| 77 | /// in mode StrRight the search starts at (hay + pos - 1) |
| 78 | /// @return Returns a pointer to the location of the character in the haystack or 0 |
| 79 | static const char* StrFind(const char* hay, char needle, S32 pos, U32 mode) |
| 80 | { |
| 81 | if (mode & String::Right) |
| 82 | { |
| 83 | // Go to the end first, then search backwards |
| 84 | const char *he = hay; |
| 85 | |
| 86 | if (pos) |
| 87 | { |
| 88 | he += pos - 1; |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | while (*he) |
| 93 | he++; |
| 94 | } |
| 95 | |
| 96 | if (mode & String::NoCase) |
| 97 | { |
| 98 | needle = dTolower(needle); |
| 99 | |
| 100 | for (; he >= hay; he--) |
| 101 | { |
| 102 | if (dTolower(*he) == needle) |
| 103 | return he; |
| 104 | } |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | for (; he >= hay; he--) |
| 109 | { |
| 110 | if (*he == needle) |
| 111 | return he; |
| 112 | } |
| 113 | } |
| 114 | return 0; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | if (mode & String::NoCase) |
| 119 | { |
| 120 | needle = dTolower(needle); |
| 121 | for (hay += pos; *hay && dTolower(*hay) != needle;) |
| 122 | hay++; |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | for (hay += pos; *hay && *hay != needle;) |
| 127 | hay++; |
| 128 | } |
| 129 | |
| 130 | return *hay ? hay : 0; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// Search for a StringData. |
| 135 | /// Search for the position of the needle in the haystack. |