mirror of
https://github.com/fluencelabs/musl
synced 2025-06-15 07:51:42 +00:00
for LC_MESSAGES, translation of strerror and similar literal message functions is supported. for messages in other places (particularly the dynamic linker) that use format strings, translation is not yet supported. in order to make it possible and safe, such messages will need to be refactored to separate the textual content from the format. for LC_TIME, the day and month names and strftime-style format strings provided by nl_langinfo are supported for translation. however there may be limitations, as some of the original C-locale nl_langinfo strings are non-unique and thus perhaps non-suitable as keys. overall, the locale support activated by this commit should not be seen as complete and polished but as a basis for beginning to test locale functionality and implement locales.
38 lines
984 B
C
38 lines
984 B
C
#include <string.h>
|
|
#include <regex.h>
|
|
#include <stdio.h>
|
|
#include "locale_impl.h"
|
|
|
|
/* Error message strings for error codes listed in `regex.h'. This list
|
|
needs to be in sync with the codes listed there, naturally. */
|
|
|
|
/* Converted to single string by Rich Felker to remove the need for
|
|
* data relocations at runtime, 27 Feb 2006. */
|
|
|
|
static const char messages[] = {
|
|
"No error\0"
|
|
"No match\0"
|
|
"Invalid regexp\0"
|
|
"Unknown collating element\0"
|
|
"Unknown character class name\0"
|
|
"Trailing backslash\0"
|
|
"Invalid back reference\0"
|
|
"Missing ']'\0"
|
|
"Missing ')'\0"
|
|
"Missing '}'\0"
|
|
"Invalid contents of {}\0"
|
|
"Invalid character range\0"
|
|
"Out of memory\0"
|
|
"Repetition not preceded by valid expression\0"
|
|
"\0Unknown error"
|
|
};
|
|
|
|
size_t regerror(int e, const regex_t *restrict preg, char *restrict buf, size_t size)
|
|
{
|
|
const char *s;
|
|
for (s=messages; e && *s; e--, s+=strlen(s)+1);
|
|
if (!*s) s++;
|
|
s = LCTRANS_CUR(s);
|
|
return 1+snprintf(buf, size, "%s", s);
|
|
}
|