* pg_wcswidth is the dumb display-width function. * It assumes that everything will appear on one line. * OTOH it is easier to use than pg_wcssize if this applies to you. */
| 174 | * OTOH it is easier to use than pg_wcssize if this applies to you. |
| 175 | */ |
| 176 | int |
| 177 | pg_wcswidth(const char *pwcs, size_t len, int encoding) |
| 178 | { |
| 179 | int width = 0; |
| 180 | |
| 181 | while (len > 0) |
| 182 | { |
| 183 | int chlen, |
| 184 | chwidth; |
| 185 | |
| 186 | chlen = PQmblen(pwcs, encoding); |
| 187 | if (len < (size_t) chlen) |
| 188 | break; /* Invalid string */ |
| 189 | |
| 190 | chwidth = PQdsplen(pwcs, encoding); |
| 191 | if (chwidth > 0) |
| 192 | width += chwidth; |
| 193 | |
| 194 | pwcs += chlen; |
| 195 | len -= chlen; |
| 196 | } |
| 197 | return width; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * pg_wcssize takes the given string in the given encoding and returns three |
no test coverage detected