cvsuser 04/11/03 13:44:39
Modified: charset ascii.c binary.c
include/parrot string_funcs.h
src string.c
Log:
Start filling in the basic ascii functions
Revision Changes Path
1.2 +63 -14 parrot/charset/ascii.c
Index: ascii.c
===================================================================
RCS file: /cvs/public/parrot/charset/ascii.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ascii.c 3 Nov 2004 20:58:08 -0000 1.1
+++ ascii.c 3 Nov 2004 21:44:37 -0000 1.2
@@ -1,6 +1,6 @@
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: ascii.c,v 1.1 2004/11/03 20:58:08 dan Exp $
+$Id: ascii.c,v 1.2 2004/11/03 21:44:37 dan Exp $
=head1 NAME
@@ -15,21 +15,22 @@
*/
#include "parrot/parrot.h"
-#include "binary.h"
+#include "ascii.h"
/* The encoding we prefer, given a choice */
static ENCODING *preferred_encoding;
static STRING *get_graphemes(Interp *interpreter, STRING *source_string, UINTVAL
offset, UINTVAL count) {
- STRING *return_string = NULL;
-
- return return_string;
+ return ENCODING_GET_BYTES(interpreter, source_string, offset, count);
}
static void set_graphemes(Interp *interpreter, STRING *source_string, UINTVAL
offset, UINTVAL replace_count, STRING *insert_string) {
+ ENCODING_SET_BYTES(interpreter, source_string, offset, replace_count,
insert_string);
+
}
static void to_charset(Interp *interpreter, STRING *source_string, CHARSET
*new_charset) {
+ internal_exception(UNIMPLEMENTED, "to_charset for ascii not implemented");
}
static STRING *copy_to_charset(Interp *interpreter, STRING *source_string, CHARSET
*new_charset) {
@@ -39,39 +40,87 @@
}
static void to_unicode(Interp *interpreter, STRING *source_string) {
- internal_exception(UNIMPLEMENTED, "to_unicode for binary not implemented");
+ internal_exception(UNIMPLEMENTED, "to_unicode for ascii not implemented");
}
-/* A noop. can't compose binary */
+/* A noop. can't compose ascii */
static void compose(Interp *interpreter, STRING *source_string) {
}
-/* A noop. can't decompose binary */
+/* A noop. can't decompose ascii */
static void decompose(Interp *interpreter, STRING *source_string) {
}
static void upcase(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't upcase binary data");
+ char *buffer;
+ UINTVAL offset = 0;
+
+ if (!source_string->strlen) {
+ return;
+ }
+
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ for (offset = 0; offset < source_string->strlen; offset++) {
+ buffer[offset] = toupper(buffer[offset]);
+ }
}
static void downcase(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't downcase binary data");
+ UINTVAL offset = 0;
+ char *buffer;
+ if (!source_string->strlen) {
+ return;
+ }
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ for (offset = 0; offset < source_string->strlen; offset++) {
+ buffer[offset] = tolower(buffer[offset]);
+ }
}
static void titlecase(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't titlecase binary data");
+ char *buffer;
+ UINTVAL offset = 0;
+ if (!source_string->strlen) {
+ return;
+ }
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ buffer[0] = toupper(buffer[0]);
+ for (offset = 1; offset < source_string->strlen; offset++) {
+ buffer[offset] = tolower(buffer[offset]);
+ }
}
static void upcase_first(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't upcase binary data");
+ char *buffer;
+ if (!source_string->strlen) {
+ return;
+ }
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ buffer[0] = toupper(buffer[0]);
}
static void downcase_first(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't downcase binary data");
+ char *buffer;
+ if (!source_string->strlen) {
+ return;
+ }
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ buffer[0] = toupper(buffer[0]);
}
static void titlecase_first(Interp *interpreter, STRING *source_string) {
- internal_error(INVALID_CHARTYPE, "Can't titlecase binary data");
+ char *buffer;
+ if (!source_string->strlen) {
+ return;
+ }
+ Parrot_unmake_COW(interpreter, source_string);
+ buffer = source_string->strstart;
+ buffer[0] = toupper(buffer[0]);
}
static INTVAL compare(Interp *interpreter, STRING *lhs, STRING *rhs) {
1.4 +5 -3 parrot/charset/binary.c
Index: binary.c
===================================================================
RCS file: /cvs/public/parrot/charset/binary.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- binary.c 3 Nov 2004 20:58:08 -0000 1.3
+++ binary.c 3 Nov 2004 21:44:37 -0000 1.4
@@ -1,6 +1,6 @@
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: binary.c,v 1.3 2004/11/03 20:58:08 dan Exp $
+$Id: binary.c,v 1.4 2004/11/03 21:44:37 dan Exp $
=head1 NAME
@@ -29,12 +29,14 @@
}
static void to_charset(Interp *interpreter, STRING *source_string, CHARSET
*new_charset) {
+ internal_exception(UNIMPLEMENTED, "to_charset for binary not implemented");
}
static STRING *copy_to_charset(Interp *interpreter, STRING *source_string, CHARSET
*new_charset) {
- STRING *return_string = NULL;
+ STRING *return_string = NULL;
+ internal_exception(UNIMPLEMENTED, "copy_to_charset for binary not implemented");
- return return_string;
+ return return_string;
}
static void to_unicode(Interp *interpreter, STRING *source_string) {
1.46 +2 -1 parrot/include/parrot/string_funcs.h
Index: string_funcs.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/string_funcs.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- string_funcs.h 18 Oct 2004 01:35:25 -0000 1.45
+++ string_funcs.h 3 Nov 2004 21:44:38 -0000 1.46
@@ -1,7 +1,7 @@
/* string_funcs.h
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: string_funcs.h,v 1.45 2004/10/18 01:35:25 brentdax Exp $
+ * $Id: string_funcs.h,v 1.46 2004/11/03 21:44:38 dan Exp $
* Overview:
* This is the api header for the string subsystem
* Data Structure and Algorithms:
@@ -17,6 +17,7 @@
/* Declarations of accessors */
+void Parrot_unmake_COW(Interp *, STRING *);
INTVAL string_compute_strlen(Interp *, STRING *);
INTVAL string_max_bytes(Interp *, STRING*, INTVAL);
STRING *string_concat(Interp *, STRING *, STRING *, UINTVAL);
1.229 +14 -14 parrot/src/string.c
Index: string.c
===================================================================
RCS file: /cvs/public/parrot/src/string.c,v
retrieving revision 1.228
retrieving revision 1.229
diff -u -r1.228 -r1.229
--- string.c 20 Oct 2004 08:03:33 -0000 1.228
+++ string.c 3 Nov 2004 21:44:39 -0000 1.229
@@ -1,6 +1,6 @@
/*
Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
-$Id: string.c,v 1.228 2004/10/20 08:03:33 leo Exp $
+$Id: string.c,v 1.229 2004/11/03 21:44:39 dan Exp $
=head1 NAME
@@ -52,7 +52,7 @@
=over 4
=item C<static void
-unmake_COW(Interp *interpreter, STRING *s)>
+Parrot_unmake_COW(Interp *interpreter, STRING *s)>
If the specified Parrot string is copy-on-write then the memory is
copied over and the copy-on-write flag is cleared.
@@ -61,8 +61,8 @@
*/
-static void
-unmake_COW(Interp *interpreter, STRING *s)
+void
+Parrot_unmake_COW(Interp *interpreter, STRING *s)
{
/* COW_FLAG | constant_FLAG | external_FLAG) */
if (PObj_is_cowed_TESTALL(s)) {
@@ -549,7 +549,7 @@
(total_length - a_capacity) + EXTRA_SIZE);
}
else {
- unmake_COW(interpreter, a);
+ Parrot_unmake_COW(interpreter, a);
}
/* A is now ready to receive the contents of B */
@@ -854,7 +854,7 @@
STRING *
string_grow(Interp * interpreter, STRING * s, INTVAL addlen)
{
- unmake_COW(interpreter,s);
+ Parrot_unmake_COW(interpreter,s);
/* Don't check buflen, if we are here, we already checked. */
Parrot_reallocate_string(interpreter,
@@ -1571,7 +1571,7 @@
if(diff >= 0
|| ((INTVAL)src->bufused - (INTVAL)PObj_buflen(src)) <= diff) {
- unmake_COW(interpreter, src);
+ Parrot_unmake_COW(interpreter, src);
if(diff != 0) {
mem_sys_memmove((char*)src->strstart + substart_off + rep->bufused,
@@ -1879,7 +1879,7 @@
else if ((*s)->strlen < len)
string_grow(interpreter, *s, len - (*s)->strlen);
else if (PObj_is_cowed_TESTALL(*s))
- unmake_COW(interpreter, *s);
+ Parrot_unmake_COW(interpreter, *s);
}
#define BITWISE_AND_STRINGS(type1, type2, restype, s1, s2, res, minlen) \
@@ -2772,7 +2772,7 @@
string_grow(interpreter, s, 1);
}
else
- unmake_COW(interpreter, s);
+ Parrot_unmake_COW(interpreter, s);
/* PObj_immobile_SET(s);
*
@@ -2857,7 +2857,7 @@
* not work for these
* so probably only sysmem should be tested
*/
- unmake_COW(interpreter, s);
+ Parrot_unmake_COW(interpreter, s);
size = PObj_buflen(s);
memory = mem_sys_allocate(size);
mem_sys_memcopy(memory, PObj_bufstart(s), size);
@@ -2892,7 +2892,7 @@
return;
}
- /* unmake_COW(interpreter, s); XXX -lt: can not be cowed ??? */
+ /* Parrot_unmake_COW(interpreter, s); XXX -lt: can not be cowed ??? */
size = PObj_buflen(s);
/* We need a handle on the fixed memory so we can get rid of it
later */
@@ -3181,7 +3181,7 @@
if (!s)
return;
- unmake_COW(interpreter, s);
+ Parrot_unmake_COW(interpreter, s);
set_char_at = set_char_setter(s);
for (i = 0; i < s->strlen; ++i) {
o = string_ord(interpreter, s, i);
@@ -3241,7 +3241,7 @@
if (!s)
return;
- unmake_COW(interpreter, s);
+ Parrot_unmake_COW(interpreter, s);
set_char_at = set_char_setter(s);
for (i = 0; i < s->strlen; ++i) {
o = string_ord(interpreter, s, i);
@@ -3301,7 +3301,7 @@
if (!s)
return;
- unmake_COW(interpreter, s);
+ Parrot_unmake_COW(interpreter, s);
set_char_at = set_char_setter(s);
o = string_ord(interpreter, s, 0);
if (o >= 'a' && o <= 'z')