forked from github/server
abkz() gets unicode
This commit is contained in:
parent
ef2f892d8a
commit
edf8f3f89d
3 changed files with 61 additions and 38 deletions
|
@ -172,12 +172,12 @@ sidename(side * s)
|
||||||
static const char *
|
static const char *
|
||||||
sideabkz(side *s, boolean truename)
|
sideabkz(side *s, boolean truename)
|
||||||
{
|
{
|
||||||
static char sideabkz_buf[4];
|
static char sideabkz_buf[8];
|
||||||
|
|
||||||
if(s->stealthfaction && truename == false) {
|
if (s->stealthfaction && truename == false) {
|
||||||
snprintf(sideabkz_buf, 4, "%s", abkz(s->stealthfaction->name, 3));
|
abkz(s->stealthfaction->name, sideabkz_buf, sizeof(sideabkz_buf), 3);
|
||||||
} else {
|
} else {
|
||||||
snprintf(sideabkz_buf, 4, "%s", abkz(s->bf->faction->name, 3));
|
abkz(s->bf->faction->name, sideabkz_buf, sizeof(sideabkz_buf), 3);
|
||||||
}
|
}
|
||||||
return sideabkz_buf;
|
return sideabkz_buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,19 +32,17 @@
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
#include "terrainid.h"
|
#include "terrainid.h"
|
||||||
|
|
||||||
/* libc includes */
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/bsdstring.h>
|
#include <util/bsdstring.h>
|
||||||
#include <util/functions.h>
|
#include <util/functions.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
#include <util/unicode.h>
|
||||||
|
|
||||||
/* Untote */
|
/* libc includes */
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
describe_braineater(unit * u, const struct locale * lang)
|
describe_braineater(unit * u, const struct locale * lang)
|
||||||
|
@ -375,69 +373,94 @@ dracoid_name(const unit *u)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** returns an abbreviation of a string.
|
||||||
|
* TODO: buflen is being ignored */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
abkz(const char *s, size_t max)
|
abkz(const char *s, char * buf, size_t buflen, size_t maxchars)
|
||||||
{
|
{
|
||||||
static char buf[32];
|
|
||||||
const char *p = s;
|
const char *p = s;
|
||||||
|
char * bufp;
|
||||||
unsigned int c = 0;
|
unsigned int c = 0;
|
||||||
size_t bpt, i;
|
size_t bpt, i;
|
||||||
|
wint_t ucs;
|
||||||
/* TODO: UNICODE. This function uses isalnum */
|
size_t size;
|
||||||
|
int result;
|
||||||
max = min(max, 79);
|
|
||||||
|
|
||||||
/* Prüfen, ob Kurz genug */
|
/* Prüfen, ob Kurz genug */
|
||||||
|
|
||||||
if (strlen(s) <= max) {
|
if (strlen(s) <= maxchars) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
/* Anzahl der Wörter feststellen */
|
/* Anzahl der Wörter feststellen */
|
||||||
|
|
||||||
while (*p != 0) {
|
while (*p != 0) {
|
||||||
/* Leerzeichen überspringen */
|
|
||||||
while (*p != 0 && !isalnum(*(unsigned char*)p))
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
p++;
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
|
||||||
/* Counter erhöhen */
|
/* Leerzeichen überspringen */
|
||||||
if (*p != 0)
|
while (*p != 0 && !iswalnum(ucs)) {
|
||||||
c++;
|
p += size;
|
||||||
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Counter erhöhen */
|
||||||
|
if (*p != 0) ++c;
|
||||||
|
|
||||||
/* alnums überspringen */
|
/* alnums überspringen */
|
||||||
while(*p != 0 && isalnum(*(unsigned char*)p))
|
while (*p != 0 && iswalnum(ucs)) {
|
||||||
p++;
|
p+=size;
|
||||||
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Buchstaben pro Teilkürzel = max(1,max/AnzWort) */
|
/* Buchstaben pro Teilkürzel = max(1,max/AnzWort) */
|
||||||
|
|
||||||
bpt = max(1, max / c);
|
bpt = max(1, maxchars / c);
|
||||||
|
|
||||||
/* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */
|
/* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */
|
||||||
|
|
||||||
p = s;
|
p = s;
|
||||||
c = 0;
|
c = 0;
|
||||||
|
bufp = buf;
|
||||||
|
|
||||||
while (*p != 0 && c < max) {
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
|
||||||
|
while (*p != 0 && c < maxchars) {
|
||||||
/* Leerzeichen überspringen */
|
/* Leerzeichen überspringen */
|
||||||
|
|
||||||
while (*p != 0 && !isalnum(*(unsigned char*)p))
|
while (*p != 0 && !iswalnum(ucs)) {
|
||||||
p++;
|
p+=size;
|
||||||
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
}
|
||||||
|
|
||||||
/* alnums übertragen */
|
/* alnums übertragen */
|
||||||
|
|
||||||
for (i = 0; i < bpt && *p != 0 && isalnum(*(unsigned char*)p); i++) {
|
for (i = 0; i < bpt && *p != 0 && iswalnum(ucs); ++i) {
|
||||||
buf[c] = *p;
|
memcpy(bufp, p, size);
|
||||||
c++;
|
p += size;
|
||||||
p++;
|
bufp += size;
|
||||||
|
++c;
|
||||||
|
|
||||||
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bis zum nächsten Leerzeichen */
|
/* Bis zum nächsten Leerzeichen */
|
||||||
|
|
||||||
while (c < max && *p != 0 && isalnum(*(unsigned char*)p))
|
while (c < maxchars && *p != 0 && iswalnum(ucs)) {
|
||||||
p++;
|
p+=size;
|
||||||
|
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||||
|
assert(result==0 || "damnit, we're not handling invalid input here!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[c] = 0;
|
*bufp = 0;
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ const char *ghoul_name(const struct unit * u);
|
||||||
const char *dragon_name(const struct unit *u);
|
const char *dragon_name(const struct unit *u);
|
||||||
const char *dracoid_name(const struct unit *u);
|
const char *dracoid_name(const struct unit *u);
|
||||||
const char *generic_name(const struct unit *u);
|
const char *generic_name(const struct unit *u);
|
||||||
const char *abkz(const char *s, size_t max);
|
const char *abkz(const char *s, char * buf, size_t size, size_t maxchars);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue