Anonymous avatar Anonymous committed 8759fba

Implement string multiplication.

Comments (0)

Files changed (1)

     return (AR)self;
 }
 
-/* invoked by AR_LIST_CONCAT */
+/* invoked by AR_STRING_CONCAT */
 AR
 _arana_api_string_concat(AR_SIG, AR self, AR other)
 {
 }
 
 static AR
+arana_string_mul(AR_SIG, AR self, AR args)
+{
+    AR other;
+    AR_PARSE(args, "I::mul", &other);
+    unsigned long times = AR_AS_LONG(other);
+    if (times < 0)
+        times = 0;
+    Ar_size_t size = AR_STRING_SIZE(self);
+    Ar_size_t totalsize = size * times;
+    char *result = AR_ALLOC(totalsize + 1);
+    char *cur = result;
+    if (!result)
+        AR_RAISE_OOM();
+    for (int i = 0; i < times; ++i) {
+        memcpy(cur, AR_AS_CHARP(self), size);
+        cur += size;
+    }
+    return AR_STRING2_NOCOPY(result, totalsize);
+}
+
+static AR
 arana_string_to_string(AR_SIG, AR self, AR args)
 {
     AR_ASSERT_EMPTY_ARGS(args, "to_string");
 {
     AR type = AR_CREATE_TYPE(ArStringType);
     AR_BIND_METHOD(type, ":concat", arana_string_concat);
+    AR_BIND_METHOD(type, ":mul", arana_string_mul);
     AR_BIND_METHOD(type, "to_string", arana_string_to_string);
     AR_BIND_METHOD(type, "to_repr", arana_string_to_repr);
     AR_BIND_METHOD(type, "get_iterator", arana_string_get_iterator);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.