Reuse lower_snake_case code for host aliases. Method host aliases for both Perl and Python use lower_snake_case, so share the implementation.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/3e9cd9e4 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/3e9cd9e4 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/3e9cd9e4 Branch: refs/heads/py_exp13 Commit: 3e9cd9e45094eea32150622467b3061e5f3e0409 Parents: 33189df Author: Marvin Humphrey <[email protected]> Authored: Mon Feb 1 16:13:09 2016 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Wed Feb 24 15:20:38 2016 -0800 ---------------------------------------------------------------------- runtime/core/Clownfish/Method.c | 26 ++++++++++++++++++++++++++ runtime/core/Clownfish/Method.cfh | 6 ++++++ runtime/perl/xs/XSBind.c | 24 +----------------------- runtime/python/cfext/CFBind.c | 4 +--- 4 files changed, 34 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3e9cd9e4/runtime/core/Clownfish/Method.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Method.c b/runtime/core/Clownfish/Method.c index c75bd4c..6bf1508 100644 --- a/runtime/core/Clownfish/Method.c +++ b/runtime/core/Clownfish/Method.c @@ -21,6 +21,7 @@ #include "Clownfish/String.h" #include "Clownfish/Err.h" #include "Clownfish/Class.h" +#include "Clownfish/CharBuf.h" Method* Method_new(String *name, cfish_method_t callback_func, uint32_t offset) { @@ -81,4 +82,29 @@ Method_Is_Excluded_From_Host_IMP(Method *self) { return self->is_excluded; } +String* +Method_lower_snake_alias(cfish_Method *method) { + cfish_String *host_alias = CFISH_Method_Get_Host_Alias(method); + if (host_alias) { + return (cfish_String*)CFISH_INCREF(host_alias); + } + // Convert to lowercase. + cfish_String *name = CFISH_Method_Get_Name(method); + cfish_CharBuf *buf = cfish_CB_new(CFISH_Str_Get_Size(name)); + cfish_StringIterator *iter = CFISH_Str_Top(name); + int32_t code_point; + while (CFISH_STR_OOB != (code_point = CFISH_StrIter_Next(iter))) { + if (code_point > 127) { + THROW(CFISH_ERR, "Can't lowercase '%o'", name); + } + else { + CFISH_CB_Cat_Char(buf, tolower(code_point)); + } + } + cfish_String *retval = CFISH_CB_Yield_String(buf); + CFISH_DECREF(iter); + CFISH_DECREF(buf); + + return retval; +} http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3e9cd9e4/runtime/core/Clownfish/Method.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Method.cfh b/runtime/core/Clownfish/Method.cfh index 3fa8633..2fc4314 100644 --- a/runtime/core/Clownfish/Method.cfh +++ b/runtime/core/Clownfish/Method.cfh @@ -53,6 +53,12 @@ final class Clownfish::Method inherits Clownfish::Obj { public void Destroy(Method *self); + + /** Return either a specified host alias or a lower-snake-case version of + * the method name. + */ + inert incremented String* + lower_snake_alias(Method *method); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3e9cd9e4/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index 813afe0..85bd85b 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -710,29 +710,7 @@ cfish_Class_find_parent_class(cfish_String *class_name) { cfish_String* CFISH_Method_Host_Name_IMP(cfish_Method *self) { - cfish_String *host_alias = CFISH_Method_Get_Host_Alias(self); - if (host_alias) { - return (cfish_String*)CFISH_INCREF(host_alias); - } - - // Convert to lowercase. - cfish_String *name = CFISH_Method_Get_Name(self); - cfish_CharBuf *buf = cfish_CB_new(CFISH_Str_Get_Size(name)); - cfish_StringIterator *iter = CFISH_Str_Top(name); - int32_t code_point; - while (CFISH_STR_OOB != (code_point = CFISH_StrIter_Next(iter))) { - if (code_point > 127) { - THROW(CFISH_ERR, "Can't lowercase '%o'", name); - } - else { - CFISH_CB_Cat_Char(buf, tolower(code_point)); - } - } - cfish_String *retval = CFISH_CB_Yield_String(buf); - CFISH_DECREF(iter); - CFISH_DECREF(buf); - - return retval; + return cfish_Method_lower_snake_alias(self); } /***************************** Clownfish::Err *******************************/ http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/3e9cd9e4/runtime/python/cfext/CFBind.c ---------------------------------------------------------------------- diff --git a/runtime/python/cfext/CFBind.c b/runtime/python/cfext/CFBind.c index 69ab9bd..99ad069 100644 --- a/runtime/python/cfext/CFBind.c +++ b/runtime/python/cfext/CFBind.c @@ -938,9 +938,7 @@ cfish_Class_find_parent_class(cfish_String *class_name) { cfish_String* CFISH_Method_Host_Name_IMP(cfish_Method *self) { - CFISH_UNUSED_VAR(self); - CFISH_THROW(CFISH_ERR, "TODO"); - CFISH_UNREACHABLE_RETURN(cfish_String*); + return cfish_Method_lower_snake_alias(self); } /**** Err ******************************************************************/
