[hackers] [libutf] fully c89 compliant || Connor Lane Smith
changeset: 1:d1a2876ecdde
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sun Apr 15 12:28:54 2012 +0100
files: utf.c utf.h utftest.c
description:
fully c89 compliant
diff -r e22069de15f9 -r d1a2876ecdde utf.c
--- a/utf.c Sat Apr 14 17:33:50 2012 +0100
+++ b/utf.c Sun Apr 15 12:28:54 2012 +0100
_AT_@ -21,9 +21,9 @@
* If the rune is illegal, runetochar will return 0.
*/
int
-runetochar(char *s, rune_t *p)
+runetochar(char *s, Rune *p)
{
- rune_t r = *p;
+ Rune r = *p;
switch(runelen(r)) {
case 1: /* 0aaaaaaa */
_AT_@ -56,7 +56,7 @@
* number of bytes in the invalid sequence.
*/
int
-chartorune(rune_t *p, const char *s)
+chartorune(Rune *p, const char *s)
{
return charntorune(p, s, UTFmax);
}
_AT_@ -71,10 +71,10 @@
* return 0.
*/
int
-charntorune(rune_t *p, const char *s, size_t len)
+charntorune(Rune *p, const char *s, size_t len)
{
unsigned int i, n;
- rune_t r;
+ Rune r;
if(len == 0) /* can't even look at s[0] */
return 0;
_AT_@ -117,7 +117,7 @@
* rune is illegal, runelen will return 0.
*/
int
-runelen(rune_t r)
+runelen(Rune r)
{
if(r <= 0x7F)
return 1;
_AT_@ -136,7 +136,7 @@
* length len pointed to by p into UTF-8.
*/
size_t
-runenlen(rune_t *p, size_t len)
+runenlen(Rune *p, size_t len)
{
size_t i, n = 0;
_AT_@ -146,13 +146,13 @@
}
/*
- * fullrune returns true if the string s of length len is long enough to be
- * decoded by chartorune, and false otherwise.
+ * fullrune returns 1 if the string s of length len is long enough to be
+ * decoded by chartorune, and 0 otherwise.
*/
-bool
+int
fullrune(const char *s, size_t len)
{
- rune_t r;
+ Rune r;
return charntorune(&r, s, len) > 0;
}
_AT_@ -166,7 +166,7 @@
char *
utfecpy(char *to, char *end, const char *from)
{
- rune_t r = Runeerror;
+ Rune r = Runeerror;
size_t i, n;
/* seek through to find final full rune */
_AT_@ -188,7 +188,7 @@
{
const char *p = s;
size_t i;
- rune_t r;
+ Rune r;
for(i = 0; *p != '\0'; i++)
p += chartorune(&r, p);
_AT_@ -206,7 +206,7 @@
{
const char *p = s;
size_t i;
- rune_t r;
+ Rune r;
int n;
for(i = 0; (n = charntorune(&r, p, len-(p-s))) && r != '\0'; i++)
_AT_@ -220,13 +220,13 @@
* considered to be part of the string s.
*/
char *
-utfrune(const char *s, rune_t r)
+utfrune(const char *s, Rune r)
{
if(r <= 0x7F) {
return strchr(s, r);
}
else if(r == Runeerror) {
- rune_t r0;
+ Rune r0;
int n;
for(; *s != '\0'; s += n) {
_AT_@ -253,10 +253,10 @@
* considered to be part of the string s.
*/
char *
-utfrrune(const char *s, rune_t r)
+utfrrune(const char *s, Rune r)
{
const char *p = NULL;
- rune_t r0;
+ Rune r0;
int n;
if(r <= 0x7F)
_AT_@ -279,7 +279,7 @@
utfutf(const char *s, const char *t)
{
const char *p, *q;
- rune_t r0, r1, r2;
+ Rune r0, r1, r2;
int n, m;
for(chartorune(&r0, t); (s = utfrune(s, r0)); s++) {
diff -r e22069de15f9 -r d1a2876ecdde utf.h
--- a/utf.h Sat Apr 14 17:33:50 2012 +0100
+++ b/utf.h Sun Apr 15 12:28:54 2012 +0100
_AT_@ -2,27 +2,25 @@
#ifndef UTF_H
#define UTF_H
-#include <stdbool.h>
#include <stddef.h>
-#include <stdint.h>
-typedef uint32_t rune_t;
+typedef unsigned int Rune;
enum {
UTFmax = 6,
Runeerror = 0xFFFD
};
-int runetochar(char *, rune_t *);
-int chartorune(rune_t *, const char *);
-int charntorune(rune_t *, const char *, size_t);
-int runelen(rune_t);
-bool fullrune(const char *, size_t);
+int runetochar(char *, Rune *);
+int chartorune(Rune *, const char *);
+int charntorune(Rune *, const char *, size_t);
+int runelen(Rune);
+int fullrune(const char *, size_t);
char *utfecpy(char *, char *, const char *);
size_t utflen(const char *);
size_t utfnlen(const char *, size_t);
-char *utfrune(const char *, rune_t);
-char *utfrrune(const char *, rune_t);
+char *utfrune(const char *, Rune);
+char *utfrrune(const char *, Rune);
char *utfutf(const char *, const char *);
#endif
diff -r e22069de15f9 -r d1a2876ecdde utftest.c
--- a/utftest.c Sat Apr 14 17:33:50 2012 +0100
+++ b/utftest.c Sun Apr 15 12:28:54 2012 +0100
_AT_@ -12,7 +12,7 @@
char buf[BUFSIZ], buf2[UTFmax], *p;
int len, len2;
size_t i, n;
- rune_t r;
+ Rune r;
switch(argc) {
case 1:
_AT_@ -93,6 +93,6 @@
fprintf(stderr, "error converting char to rune:");
for(i = 0; i < n; i++)
- fprintf(stderr, " %02X", (uint8_t)s[i]);
+ fprintf(stderr, " %02X", (unsigned char)s[i]);
fputc('\n', stderr);
}
Received on Sun Apr 15 2012 - 13:46:50 CEST
This archive was generated by hypermail 2.3.0
: Sun Apr 15 2012 - 13:48:06 CEST