summaryrefslogtreecommitdiff
path: root/src/ntriples_parse.c
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2013-08-11 14:43:51 -0700
committerDave Beckett <dave@dajobe.org>2013-08-11 19:46:47 -0700
commit7b4788f656546be7abdd87122c03ea005e771c17 (patch)
tree896b2ce80ca8f31ace5bf66d2642b1bf713ed75b /src/ntriples_parse.c
parent2602d48a726aaf8d901a4720b771b6c49254d37a (diff)
downloadraptor-7b4788f656546be7abdd87122c03ea005e771c17.tar.gz
(raptor_normalize_language): Added to normalize to en-US-BLAH
Diffstat (limited to 'src/ntriples_parse.c')
-rw-r--r--src/ntriples_parse.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/ntriples_parse.c b/src/ntriples_parse.c
index 0e2da00a..84e62ed7 100644
--- a/src/ntriples_parse.c
+++ b/src/ntriples_parse.c
@@ -256,10 +256,12 @@ raptor_ntriples_generate_statement(raptor_parser* parser,
/* These are for 7-bit ASCII and not locale-specific */
#define IS_ASCII_ALPHA(c) (((c) > 0x40 && (c) < 0x5B) || ((c) > 0x60 && (c) < 0x7B))
+#define IS_ASCII_LOWER(c) ((c) > 0x60 && (c) < 0x7B)
#define IS_ASCII_UPPER(c) ((c) > 0x40 && (c) < 0x5B)
#define IS_ASCII_DIGIT(c) ((c) > 0x2F && (c) < 0x3A)
#define IS_ASCII_PRINT(c) ((c) > 0x1F && (c) < 0x7F)
-#define TO_ASCII_LOWER(c) ((c)+0x20)
+#define TO_ASCII_LOWER(c) ((c) + 0x20)
+#define TO_ASCII_UPPER(c) ((c) - 0x20)
typedef enum {
RAPTOR_TERM_CLASS_URI, /* ends on > */
@@ -535,6 +537,44 @@ raptor_ntriples_term(raptor_parser* rdf_parser,
#define MAX_NTRIPLES_TERMS 4
+/*
+ * raptor_normalize_language:
+ * @language: language
+ *
+ * INTERNAL - Normalize language to lowercase
+ *
+ * http://www.w3.org/TR/rdf-concepts/#dfn-language-identifier
+ *
+ * Return value: non-0 if normalized
+ */
+int
+raptor_normalize_language(char* language)
+{
+ char *p;
+ int seen_ = 0;
+ int normalized = 0;
+
+ if(!language)
+ return 0;
+
+ for(p = language; *p; p++) {
+ if(*p == '-')
+ seen_ ++;
+ else if(!seen_) {
+ if(IS_ASCII_UPPER(*p)) {
+ *p = TO_ASCII_LOWER(*p);
+ normalized = 1;
+ }
+ } else if(IS_ASCII_LOWER(*p)) {
+ *p = TO_ASCII_UPPER(*p);
+ normalized = 1;
+ }
+ }
+
+ return normalized;
+}
+
+
static int
raptor_ntriples_parse_line(raptor_parser* rdf_parser,
unsigned char *buffer, size_t len,