Created
January 16, 2012 02:16
-
-
Save pedrofaria/1618680 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/types/str.cc b/types/str.cc | |
index a6ca0d1..cf86912 100644 | |
--- a/types/str.cc | |
+++ b/types/str.cc | |
@@ -29,6 +29,18 @@ | |
#include "types/str.h" | |
namespace clever { | |
+ | |
+/** | |
+ * String:trim() | |
+ */ | |
+CLEVER_TYPE_METHOD(String::ltrim) { | |
+} | |
+ | |
+CLEVER_TYPE_METHOD(String::rtrim) { | |
+} | |
+ | |
+CLEVER_TYPE_METHOD(String::trim) { | |
+} | |
/** | |
* String:replace() | |
@@ -112,6 +124,18 @@ CLEVER_TYPE_METHOD(String::constructor) { | |
} | |
} | |
+CLEVER_TYPE_METHOD(String::toUpper) { | |
+ std::string str = CLEVER_THIS()->toString(); | |
+ std::transform(str.begin(), str.end(),str.begin(), ::toupper); | |
+ CLEVER_RETURN_STR(CSTRING(str)); | |
+} | |
+ | |
+CLEVER_TYPE_METHOD(String::toLower) { | |
+ std::string str = CLEVER_THIS()->toString(); | |
+ std::transform(str.begin(), str.end(),str.begin(), ::tolower); | |
+ CLEVER_RETURN_STR(CSTRING(str)); | |
+} | |
+ | |
/** | |
* + operator (String, String) | |
*/ | |
@@ -163,6 +187,12 @@ CLEVER_TYPE_METHOD(String::less) { | |
void String::init() { | |
addMethod(new Method(CLEVER_CTOR_NAME, (MethodPtr)&String::constructor, CLEVER_STR)); | |
+ | |
+ addMethod(new Method("ltrim", (MethodPtr)&String::ltrim, CLEVER_STR)); | |
+ | |
+ addMethod(new Method("rtrim", (MethodPtr)&String::rtrim, CLEVER_STR)); | |
+ | |
+ addMethod(new Method("trim", (MethodPtr)&String::trim, CLEVER_STR)); | |
addMethod( | |
(new Method(CLEVER_OPERATOR_EQUAL, (MethodPtr)&String::equal, CLEVER_BOOL)) | |
@@ -214,6 +244,10 @@ void String::init() { | |
addMethod(new Method("toDouble", (MethodPtr)&String::toDouble, CLEVER_DOUBLE)); | |
addMethod(new Method("toInteger", (MethodPtr)&String::toInteger, CLEVER_INT)); | |
+ | |
+ addMethod(new Method("toUpper", (MethodPtr)&String::toUpper, CLEVER_STR)); | |
+ | |
+ addMethod(new Method("toLower", (MethodPtr)&String::toLower, CLEVER_STR)); | |
} | |
DataValue* String::allocateValue() const { | |
diff --git a/types/str.h b/types/str.h | |
index 8a4f621..3907e7b 100644 | |
--- a/types/str.h | |
+++ b/types/str.h | |
@@ -43,10 +43,15 @@ public: | |
* Type methods | |
*/ | |
static CLEVER_TYPE_METHOD(constructor); | |
+ static CLEVER_TYPE_METHOD(ltrim); | |
+ static CLEVER_TYPE_METHOD(rtrim); | |
+ static CLEVER_TYPE_METHOD(trim); | |
static CLEVER_TYPE_METHOD(replace); | |
static CLEVER_TYPE_METHOD(substring); | |
static CLEVER_TYPE_METHOD(toDouble); | |
static CLEVER_TYPE_METHOD(toInteger); | |
+ static CLEVER_TYPE_METHOD(toUpper); | |
+ static CLEVER_TYPE_METHOD(toLower); | |
/** | |
* Type operator methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment