diff options
author | Tatsuo Ishii <ishii@postgresql.org> | 2001-07-15 11:07:37 +0000 |
---|---|---|
committer | Tatsuo Ishii <ishii@postgresql.org> | 2001-07-15 11:07:37 +0000 |
commit | 1032445e5d9ca0659e725c2203291a5ea898d0de (patch) | |
tree | 80ffb9d6e52e4899cd1783704b31d2fcfe571a3b /src/backend/utils/mb/mbutils.c | |
parent | b08e86d557538c16e482ad10a9bdbc474893d07e (diff) | |
download | postgresql-1032445e5d9ca0659e725c2203291a5ea898d0de.tar.gz postgresql-1032445e5d9ca0659e725c2203291a5ea898d0de.zip |
TODO item:
* Make n of CHAR(n)/VARCHAR(n) the number of letters, not bytes
Diffstat (limited to 'src/backend/utils/mb/mbutils.c')
-rw-r--r-- | src/backend/utils/mb/mbutils.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c index c355bf1e414..7b5262da6c4 100644 --- a/src/backend/utils/mb/mbutils.c +++ b/src/backend/utils/mb/mbutils.c @@ -3,7 +3,7 @@ * client encoding and server internal encoding. * (currently mule internal code (mic) is used) * Tatsuo Ishii - * $Id: mbutils.c,v 1.17 2001/04/16 02:42:01 tgl Exp $ + * $Id: mbutils.c,v 1.18 2001/07/15 11:07:36 ishii Exp $ */ #include "postgres.h" @@ -241,9 +241,9 @@ pg_mbstrlen_with_len(const unsigned char *mbstr, int limit) } /* - * returns the length of a multi-byte string + * returns the byte length of a multi-byte string * (not necessarily NULL terminated) - * that is not longer than limit. + * that is no longer than limit. * this function does not break multi-byte word boundary. */ int @@ -267,8 +267,30 @@ pg_mbcliplen(const unsigned char *mbstr, int len, int limit) } /* - * functions for utils/init - */ + * Similar to pg_mbcliplen but the limit parameter specifies the + * character length, not the byte length. */ +int +pg_mbcharcliplen(const unsigned char *mbstr, int len, int limit) +{ + int clen = 0; + int nch = 0; + int l; + + while (len > 0 && *mbstr) + { + l = pg_mblen(mbstr); + nch++; + if (nch > limit) + break; + clen += l; + len -= l; + mbstr += l; + } + return (clen); +} + +/* + * functions for utils/init */ static int DatabaseEncoding = MULTIBYTE; void |