textaux_CopyTextLine This function goes hand-in-hand with textaux_WordWrap(). Given a buffer of data it will fill in the dest buffer until it hits a /n or /0. It returns a pointer to the start position of the next line, or NULL if it's done with the buffer (it hit a /0).
| 123 | // the dest buffer until it hits a /n or /0. It returns a pointer to the start position of the next line, |
| 124 | // or NULL if it's done with the buffer (it hit a /0). |
| 125 | const char *textaux_CopyTextLine(const char *src, char *dest) { |
| 126 | // make sure src and dest are allocated |
| 127 | if (!src) { |
| 128 | if (dest) |
| 129 | dest[0] = '\0'; |
| 130 | return nullptr; |
| 131 | } |
| 132 | if (!dest) |
| 133 | return nullptr; |
| 134 | // see if we are at the end of the src |
| 135 | if (src[0] == '\0') { |
| 136 | dest[0] = '\0'; |
| 137 | return nullptr; |
| 138 | } |
| 139 | int i; |
| 140 | i = 0; |
| 141 | // find the end |
| 142 | while ((src[i] != '\n') && (src[i] != '\0')) |
| 143 | i++; |
| 144 | if (src[i] == '\0') { |
| 145 | // no more lines left after this |
| 146 | strncpy(dest, src, i); |
| 147 | dest[i] = '\0'; |
| 148 | return nullptr; |
| 149 | } else { |
| 150 | // we hit a newline char |
| 151 | strncpy(dest, src, i); |
| 152 | dest[i] = '\0'; |
| 153 | i++; |
| 154 | return &src[i]; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // textaux_ClipString |
| 159 | // Given a width (in pixels), and a string, this function will truncate the string |
no outgoing calls
no test coverage detected