On Sat, 10 Nov 2001, Jeff wrote:
> string.pasm patches the operators mentioned
> The other file, 'parrot.pasm', is a miniature Parrot compiler, written
> in Parrot.
>
> The patches in the string.diff file are required to make this work.
ook, cool, but string_length returns an INTVAL, not an int.
Alex Gough
diff -ru parrot_orig/string.c parrot/string.c
--- parrot_orig/string.c Wed Oct 31 17:51:31 2001
+++ parrot/string.c Sat Nov 10 18:16:27 2001
@@ -83,6 +83,33 @@
return s->strlen;
}
+/*=for api string string_ord
+ * return the length of the string
+ */
+INTVAL
+string_ord(STRING* s, INTVAL index) {
+ if(s==NULL) {
+ INTERNAL_EXCEPTION(ORD_OUT_OF_STRING,
+ "Cannot get character of empty string");
+ }
+ else {
+ INTVAL len = string_length(s);
+ if(index < 0) {
+ INTERNAL_EXCEPTION(ORD_OUT_OF_STRING,
+ "Cannot get character at negative index");
+ }
+ else if(index > (len - 1)) {
+ INTERNAL_EXCEPTION(ORD_OUT_OF_STRING,
+ "Cannot get character past end of string");
+ }
+ else {
+ char *buf = s->bufstart;
+ return buf[index];
+ }
+ }
+ return -1;
+}
+
/*=for api string string_copy
* create a copy of the argument passed in
*/
@@ -175,13 +202,19 @@
*/
STRING*
string_concat(struct Parrot_Interp *interpreter, STRING* a, STRING* b, INTVAL flags) {
- if (a->type != b->type || a->encoding != b->encoding) {
- b = string_transcode(interpreter, b, a->encoding, a->type, NULL);
+ if(a != NULL) {
+ if (a->type != b->type || a->encoding != b->encoding) {
+ b = string_transcode(interpreter, b, a->encoding, a->type, NULL);
+ }
+ string_grow(a, a->strlen + b->strlen);
+ mem_sys_memcopy((void*)((ptrcast_t)a->bufstart + a->bufused),b->bufstart,
+b->bufused);
+ a->strlen = a->strlen + b->strlen;
+ a->bufused = a->bufused + b->bufused;
+ }
+ else {
+ return string_make(interpreter,
+ b->bufstart,b->buflen,b->encoding,flags,b->type);
}
- string_grow(a, a->strlen + b->strlen);
- mem_sys_memcopy((void*)((ptrcast_t)a->bufstart + a->bufused),
b->bufstart,b->bufused);
- a->strlen = a->strlen + b->strlen;
- a->bufused = a->bufused + b->bufused;
return a;
}