summaryrefslogtreecommitdiff
path: root/gl/lib/mbsalign.h
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-03-15 14:04:31 +0000
committerPádraig Brady <P@draigBrady.com>2010-03-19 19:23:45 +0000
commitdfe0d336a00940c8e13c24b6d5d7485a2d7310b0 (patch)
treede0b56d0af4ba442f070cef2ec717de9c4066a48 /gl/lib/mbsalign.h
parent3dcbcf98f427f8ab6ceafd27396adae4b2276bb8 (diff)
downloadcoreutils-dfe0d336a00940c8e13c24b6d5d7485a2d7310b0.tar.xz
maint: update the mbsalign module
* gl/lib/mbsalign.c (mbsalign): Support the MBA_UNIBYTE_FALLBACK flag which reverts to unibyte mode if one can't allocate memory or if there are invalid multibyte characters present. Note memory is no longer dynamically allocated in unibyte mode so one can assume that mbsalign() will not return an error if this flag is present. Don't calculate twice, the number of spaces, when centering. Suppress a signed/unsigned comparison warning. (ambsalign): A new wrapper function to dynamically allocate the minimum memory required to hold the aligned string. * gl/lib/mbsalign.h: Add the MBA_UNIBYTE_FALLBACK flag and also document others that may be implemented in future. (ambsalign): A prototype for the new wrapper. * gl/tests/test-mbsalign.c (main): New test program. * gl/modules/mbsalign-tests: A new index to reference the tests. * .x-sc_program_name: Exclude test-mbsalign.c from this check.
Diffstat (limited to 'gl/lib/mbsalign.h')
-rw-r--r--gl/lib/mbsalign.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/gl/lib/mbsalign.h b/gl/lib/mbsalign.h
index a4ec69395..41bd49092 100644
--- a/gl/lib/mbsalign.h
+++ b/gl/lib/mbsalign.h
@@ -18,6 +18,29 @@
typedef enum { MBS_ALIGN_LEFT, MBS_ALIGN_RIGHT, MBS_ALIGN_CENTER } mbs_align_t;
+enum {
+ /* Use unibyte mode for invalid multibyte strings or
+ or when heap memory is exhausted. */
+ MBA_UNIBYTE_FALLBACK = 0x0001,
+
+#if 0 /* Other possible options. */
+ /* Skip invalid multibyte chars rather than failing */
+ MBA_IGNORE_INVALID = 0x0002,
+
+ /* Align multibyte strings using "figure space" (\u2007) */
+ MBA_USE_FIGURE_SPACE = 0x0004,
+
+ /* Don't add any padding */
+ MBA_TRUNCATE_ONLY = 0x0008,
+
+ /* Don't truncate */
+ MBA_PAD_ONLY = 0x0010,
+#endif
+};
+
size_t
mbsalign (const char *src, char *dest, size_t dest_size,
size_t *width, mbs_align_t align, int flags);
+
+char *
+ambsalign (const char *src, size_t *width, mbs_align_t align, int flags);