MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_wcssize

Function pg_wcssize

src/fe_utils/mbprint.c:210–285  ·  view source on GitHub ↗

* pg_wcssize takes the given string in the given encoding and returns three * values: * result_width: Width in display characters of the longest line in string * result_height: Number of lines in display output * result_format_size: Number of bytes required to store formatted * representation of string * * This MUST be kept in sync with pg_wcsformat! */

Source from the content-addressed store, hash-verified

208 * This MUST be kept in sync with pg_wcsformat!
209 */
210void
211pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
212 int *result_width, int *result_height, int *result_format_size)
213{
214 int w,
215 chlen = 0,
216 linewidth = 0;
217 int width = 0;
218 int height = 1;
219 int format_size = 0;
220
221 for (; *pwcs && len > 0; pwcs += chlen)
222 {
223 chlen = PQmblen((const char *) pwcs, encoding);
224 if (len < (size_t) chlen)
225 break;
226 w = PQdsplen((const char *) pwcs, encoding);
227
228 if (chlen == 1) /* single-byte char */
229 {
230 if (*pwcs == '\n') /* Newline */
231 {
232 if (linewidth > width)
233 width = linewidth;
234 linewidth = 0;
235 height += 1;
236 format_size += 1; /* For NUL char */
237 }
238 else if (*pwcs == '\r') /* Linefeed */
239 {
240 linewidth += 2;
241 format_size += 2;
242 }
243 else if (*pwcs == '\t') /* Tab */
244 {
245 do
246 {
247 linewidth++;
248 format_size++;
249 } while (linewidth % 8 != 0);
250 }
251 else if (w < 0) /* Other control char */
252 {
253 linewidth += 4;
254 format_size += 4;
255 }
256 else /* Output it as-is */
257 {
258 linewidth += w;
259 format_size += 1;
260 }
261 }
262 else if (w < 0) /* Non-ascii control char */
263 {
264 linewidth += 6; /* \u0000 */
265 format_size += 6;
266 }
267 else /* All other chars */

Callers 2

print_aligned_textFunction · 0.85
print_aligned_verticalFunction · 0.85

Calls 2

PQmblenFunction · 0.85
PQdsplenFunction · 0.85

Tested by

no test coverage detected