forked from github/server
add a string escaping function.
start some work on nrmessage.c.
This commit is contained in:
parent
35c3d4cda0
commit
9ca945cb2c
|
@ -3,7 +3,10 @@ msgstr "Rostiges Kettenhemd"
|
|||
|
||||
msgctxt "spellinfo"
|
||||
msgid "destroy_magic"
|
||||
msgstr "Dieser Zauber ermöglicht dem Magier, Verzauberungen einer Einheit, eines Schiffes, Gebäudes oder auch der Region aufzulösen."
|
||||
msgstr ""
|
||||
"Dieser Zauber ermöglicht dem Magier, Verzauberungen "
|
||||
"einer Einheit, eines Schiffes, Gebäudes oder auch "
|
||||
"der Region aufzulösen."
|
||||
|
||||
msgctxt "spell"
|
||||
msgid "shadowknights"
|
||||
|
|
|
@ -32,7 +32,10 @@ static nrmessage_type *nrtypes[NRT_MAXHASH];
|
|||
|
||||
const char *nrt_string(const struct nrmessage_type *type)
|
||||
{
|
||||
return type->string;
|
||||
if (type->string) {
|
||||
return type->string;
|
||||
}
|
||||
return locale_get(type->lang, type->mtype->name);
|
||||
}
|
||||
|
||||
nrmessage_type *nrt_find(const struct locale * lang,
|
||||
|
@ -148,7 +151,7 @@ size_t size, const void *userdata)
|
|||
|
||||
if (nrt) {
|
||||
const char *m =
|
||||
translate(nrt->string, userdata, nrt->vars, msg->parameters);
|
||||
translate(nrt_string(nrt), userdata, nrt->vars, msg->parameters);
|
||||
if (m) {
|
||||
return str_strlcpy((char *)buffer, m, size);
|
||||
}
|
||||
|
|
|
@ -270,3 +270,38 @@ void sbs_strcpy(struct sbstring *sbs, const char *str)
|
|||
}
|
||||
sbs->end = sbs->begin + len;
|
||||
}
|
||||
|
||||
char *str_unescape(char *str) {
|
||||
char *read = str, *write = str;
|
||||
while (*read) {
|
||||
char * pos = strchr(read, '\\');
|
||||
if (pos) {
|
||||
size_t len = pos - read;
|
||||
memmove(write, read, len);
|
||||
write += len;
|
||||
read += (len + 1);
|
||||
switch (read[0]) {
|
||||
case 'r':
|
||||
*write++ = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
*write++ = '\n';
|
||||
break;
|
||||
case 't':
|
||||
*write++ = '\t';
|
||||
break;
|
||||
default:
|
||||
*write++ = read[0];
|
||||
}
|
||||
*write = 0;
|
||||
++read;
|
||||
}
|
||||
else {
|
||||
size_t len = strlen(read);
|
||||
memmove(write, read, len);
|
||||
write[len] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -26,13 +26,15 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value);
|
||||
const char *str_escape(const char *str, char *buffer, size_t len);
|
||||
unsigned int str_hash(const char *s);
|
||||
size_t str_slprintf(char * dst, size_t size, const char * format, ...);
|
||||
size_t str_strlcpy(char *dst, const char *src, size_t len);
|
||||
size_t str_strlcat(char *dst, const char *src, size_t len);
|
||||
char *str_strdup(const char *s);
|
||||
|
||||
const char *str_escape(const char *str, char *buffer, size_t len);
|
||||
char *str_unescape(char *str);
|
||||
|
||||
unsigned int jenkins_hash(unsigned int a);
|
||||
unsigned int wang_hash(unsigned int a);
|
||||
|
||||
|
|
|
@ -9,6 +9,19 @@
|
|||
#include <string.h>
|
||||
#include "strings.h"
|
||||
|
||||
static void test_str_unescape(CuTest * tc)
|
||||
{
|
||||
char scratch[64];
|
||||
|
||||
strcpy(scratch, "1234 5678");
|
||||
str_unescape(scratch);
|
||||
CuAssertStrEquals(tc, "1234 5678", scratch);
|
||||
|
||||
strcpy(scratch, "\\\"\\\\\\n\\t\\r\\a");
|
||||
str_unescape(scratch);
|
||||
CuAssertStrEquals(tc, "\"\\\n\t\ra", scratch);
|
||||
}
|
||||
|
||||
static void test_str_escape(CuTest * tc)
|
||||
{
|
||||
char scratch[64];
|
||||
|
@ -122,6 +135,7 @@ CuSuite *get_strings_suite(void)
|
|||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_str_hash);
|
||||
SUITE_ADD_TEST(suite, test_str_escape);
|
||||
SUITE_ADD_TEST(suite, test_str_unescape);
|
||||
SUITE_ADD_TEST(suite, test_str_replace);
|
||||
SUITE_ADD_TEST(suite, test_str_slprintf);
|
||||
SUITE_ADD_TEST(suite, test_str_strlcat);
|
||||
|
|
|
@ -10,12 +10,23 @@ This program may not be used, modified or distributed
|
|||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#endif
|
||||
|
||||
#include "xmlreader.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "guard.h"
|
||||
#include "keyword.h"
|
||||
#include "move.h"
|
||||
#include "prefix.h"
|
||||
|
||||
#include "attributes/attributes.h"
|
||||
#include "modules/score.h"
|
||||
|
||||
#include "kernel/building.h"
|
||||
#include "kernel/calendar.h"
|
||||
#include "kernel/item.h"
|
||||
#include "kernel/messages.h"
|
||||
#include "kernel/race.h"
|
||||
|
@ -27,26 +38,15 @@ without prior permission by the authors of Eressea.
|
|||
#include "kernel/spell.h"
|
||||
#include "kernel/spellbook.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "kernel/calendar.h"
|
||||
#include "guard.h"
|
||||
#include "keyword.h"
|
||||
#include "move.h"
|
||||
#include "prefix.h"
|
||||
|
||||
#include <modules/score.h>
|
||||
#include <attributes/attributes.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/crmessage.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/xml.h>
|
||||
#include "util/attrib.h"
|
||||
#include "util/crmessage.h"
|
||||
#include "util/functions.h"
|
||||
#include "util/language.h"
|
||||
#include "util/log.h"
|
||||
#include "util/message.h"
|
||||
#include "util/nrmessage.h"
|
||||
#include "util/strings.h"
|
||||
#include "util/xml.h"
|
||||
|
||||
/* libxml includes */
|
||||
#include <libxml/tree.h>
|
||||
|
|
Loading…
Reference in New Issue