lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [13/15] git commit: refs/heads/cfish-string-prep1 - Introduce Str_new_from_char
Date Mon, 02 Sep 2013 19:16:44 GMT
Introduce Str_new_from_char


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ee8b20d5
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ee8b20d5
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ee8b20d5

Branch: refs/heads/cfish-string-prep1
Commit: ee8b20d55fc566c6d99a481e4d5e2da7e670aa92
Parents: 0f0ec86
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Sep 2 20:19:40 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Sep 2 21:12:30 2013 +0200

----------------------------------------------------------------------
 clownfish/runtime/core/Clownfish/String.c   | 11 +++++++++++
 clownfish/runtime/core/Clownfish/String.cfh |  5 +++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/ee8b20d5/clownfish/runtime/core/Clownfish/String.c
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.c b/clownfish/runtime/core/Clownfish/String.c
index a2f0a3f..2a46393 100644
--- a/clownfish/runtime/core/Clownfish/String.c
+++ b/clownfish/runtime/core/Clownfish/String.c
@@ -118,6 +118,17 @@ Str_new_steal_str(char *ptr, size_t size, size_t cap) {
 }
 
 String*
+Str_new_from_char(uint32_t code_point) {
+    const size_t MAX_UTF8_BYTES = 4;
+    String *self = (String*)VTable_Make_Obj(STRING);
+    self->ptr  = (char*)MALLOCATE(MAX_UTF8_BYTES + 1);
+    self->cap  = MAX_UTF8_BYTES + 1;
+    self->size = StrHelp_encode_utf8_char(code_point, (uint8_t*)self->ptr);
+    self->ptr[self->size] = '\0';
+    return self;
+}
+
+String*
 Str_newf(const char *pattern, ...) {
     String *self = Str_new(strlen(pattern));
     va_list args;

http://git-wip-us.apache.org/repos/asf/lucy/blob/ee8b20d5/clownfish/runtime/core/Clownfish/String.cfh
----------------------------------------------------------------------
diff --git a/clownfish/runtime/core/Clownfish/String.cfh b/clownfish/runtime/core/Clownfish/String.cfh
index 529cc70..db8689b 100644
--- a/clownfish/runtime/core/Clownfish/String.cfh
+++ b/clownfish/runtime/core/Clownfish/String.cfh
@@ -64,6 +64,11 @@ class Clownfish::String cnick Str
     init_steal_trusted_str(decremented String *self, char *ptr,
                            size_t size, size_t cap);
 
+    /** Return a String which holds a single character.
+     */
+    inert incremented String*
+    new_from_char(uint32_t code_point);
+
     /** Return a pointer to a new String which contains formatted data
      * expanded according to Str_VCatF.
      *


Mime
View raw message