cvsuser 05/02/27 04:12:29
Modified: encodings fixed_8.c
include/parrot encoding.h
src encoding.c
Log:
the big string patch 3 - encoding cleanup
* pdd07
* fiy bytes()
Revision Changes Path
1.7 +115 -72 parrot/encodings/fixed_8.c
Index: fixed_8.c
===================================================================
RCS file: /cvs/public/parrot/encodings/fixed_8.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- fixed_8.c 27 Feb 2005 09:58:42 -0000 1.6
+++ fixed_8.c 27 Feb 2005 12:12:25 -0000 1.7
@@no-spam -1,6 +1,6 @@no-spam
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: fixed_8.c,v 1.6 2005/02/27 09:58:42 leo Exp $
+$Id: fixed_8.c,v 1.7 2005/02/27 12:12:25 leo Exp $
=head1 NAME
@@no-spam -19,53 +19,76 @@no-spam
/* This function needs to go through and get all the code points one
by one and turn them into a byte */
-static void to_encoding(Interp *interpreter, STRING *source_string) {
+static void
+to_encoding(Interp *interpreter, STRING *source_string)
+{
}
-static STRING *copy_to_encoding(Interp *interpreter, STRING *source_string) {
- STRING *return_string = NULL;
+static STRING *
+copy_to_encoding(Interp *interpreter, STRING *source_string)
+{
+ STRING *return_string = NULL;
- return return_string;
+ return return_string;
}
/* codepoints are bytes, so delegate */
-static UINTVAL get_codepoint(Interp *interpreter, const STRING *source_string, UINTVAL offset) {
- return get_byte(interpreter, source_string, offset);
+static UINTVAL
+get_codepoint(Interp *interpreter, const STRING *source_string,
+ UINTVAL offset)
+{
+ return get_byte(interpreter, source_string, offset);
}
/* This is the same as set byte */
-static void set_codepoint(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL codepoint) {
- set_byte(interpreter, source_string, offset, codepoint);
-}
-
-static UINTVAL get_byte(Interp *interpreter, const STRING *source_string, UINTVAL offset) {
- char *contents = source_string->strstart;
- if (offset >= source_string->bufused) {
- assert(offset < source_string->bufused);
- internal_exception(0, "get_byte past the end of the buffer (%i of %i)", offset, source_string->bufused);
- }
- return contents[offset];
-}
-
-static void set_byte(Interp *interpreter, const STRING *source_string, UINTVAL offset, UINTVAL byte) {
- char *contents;
- if (offset >= source_string->bufused) {
- internal_exception(0, "set_byte past the end of the buffer");
- }
- contents = source_string->strstart;
- contents[offset] = byte;
-
+static void
+set_codepoint(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL codepoint)
+{
+ set_byte(interpreter, source_string, offset, codepoint);
+}
+
+static UINTVAL
+get_byte(Interp *interpreter, const STRING *source_string, UINTVAL offset)
+{
+ char *contents = source_string->strstart;
+ if (offset >= source_string->bufused) {
+ internal_exception(0,
+ "get_byte past the end of the buffer (%i of %i)",
+ offset, source_string->bufused);
+ }
+ return contents[offset];
+}
+
+static void
+set_byte(Interp *interpreter, const STRING *source_string,
+ UINTVAL offset, UINTVAL byte)
+{
+ char *contents;
+ if (offset >= source_string->bufused) {
+ internal_exception(0, "set_byte past the end of the buffer");
+ }
+ contents = source_string->strstart;
+ contents[offset] = byte;
}
/* Delegate to get_bytes */
-static STRING *get_codepoints(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL count) {
- STRING *return_string = get_bytes(interpreter, source_string, offset, count);
+static STRING *
+get_codepoints(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL count)
+{
+ STRING *return_string = get_bytes(interpreter, source_string,
+ offset, count);
return_string->charset = source_string->charset;
return return_string;
}
-static STRING *get_bytes(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL count) {
- STRING *return_string = Parrot_make_COW_reference(interpreter, source_string);
+static STRING *
+get_bytes(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL count)
+{
+ STRING *return_string = Parrot_make_COW_reference(interpreter,
+ source_string);
return_string->encoding = source_string->encoding;
return_string->charset = source_string->charset;
@@no-spam -80,12 +103,19 @@no-spam
/* Delegate to get_bytes */
-static STRING *get_codepoints_inplace(Interp *interpreter, STRING *source_string, STRING *dest_string, UINTVAL offset, UINTVAL count) {
-
- return get_bytes_inplace(interpreter, source_string, offset, count, dest_string);
+static STRING *
+get_codepoints_inplace(Interp *interpreter, STRING *source_string,
+ STRING *dest_string, UINTVAL offset, UINTVAL count)
+{
+
+ return get_bytes_inplace(interpreter, source_string, offset,
+ count, dest_string);
}
-static STRING *get_bytes_inplace(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *return_string) {
+static STRING *
+get_bytes_inplace(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL count, STRING *return_string)
+{
Parrot_reuse_COW_reference(interpreter, source_string, return_string);
return_string->encoding = source_string->encoding;
return_string->charset = source_string->charset;
@@no-spam -96,58 +126,71 @@no-spam
return_string->strlen = count;
return_string->hashval = 0;
- return return_string;
+ return return_string;
}
/* Delegate to set_bytes */
-static void set_codepoints(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_codepoints) {
- set_bytes(interpreter, source_string, offset, count, new_codepoints);
+static void
+set_codepoints(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL count, STRING *new_codepoints)
+{
+ set_bytes(interpreter, source_string, offset, count, new_codepoints);
}
-static void set_bytes(Interp *interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_bytes) {
+static void
+set_bytes(Interp *interpreter, STRING *source_string,
+ UINTVAL offset, UINTVAL count, STRING *new_bytes)
+{
string_replace(interpreter, source_string, offset, count, new_bytes, NULL);
}
/* Unconditionally makes the string be in this encoding, if that's
valid */
-static void become_encoding(Interp *interpreter, STRING *source_string) {
+static void
+become_encoding(Interp *interpreter, STRING *source_string)
+{
}
-static UINTVAL codepoints(Interp *interpreter, STRING *source_string) {
+static UINTVAL
+codepoints(Interp *interpreter, STRING *source_string)
+{
return bytes(interpreter, source_string);
}
-static UINTVAL bytes(Interp *interpreter, STRING *source_string) {
- return source_string->bufused -
- ((char *)source_string->strstart - (char *)PObj_bufstart(source_string));
-}
-
-ENCODING *Parrot_encoding_fixed_8_init(Interp *interpreter) {
- ENCODING *return_encoding = Parrot_new_encoding(interpreter);
-
- ENCODING base_encoding = {
- "fixed_8",
- 1, /* Max bytes per codepoint */
- to_encoding,
- copy_to_encoding,
- get_codepoint,
- set_codepoint,
- get_byte,
- set_byte,
- get_codepoints,
- get_codepoints_inplace,
- get_bytes,
- get_bytes_inplace,
- set_codepoints,
- set_bytes,
- become_encoding,
- codepoints,
- bytes
- };
- memcpy(return_encoding, &base_encoding, sizeof(ENCODING));
- Parrot_register_encoding(interpreter, "fixed_8", return_encoding);
- return return_encoding;
+static UINTVAL
+bytes(Interp *interpreter, STRING *source_string)
+{
+ return source_string->bufused;
+}
+
+ENCODING *
+Parrot_encoding_fixed_8_init(Interp *interpreter)
+{
+ ENCODING *return_encoding = Parrot_new_encoding(interpreter);
+
+ ENCODING base_encoding = {
+ "fixed_8",
+ 1, /* Max bytes per codepoint */
+ to_encoding,
+ copy_to_encoding,
+ get_codepoint,
+ set_codepoint,
+ get_byte,
+ set_byte,
+ get_codepoints,
+ get_codepoints_inplace,
+ get_bytes,
+ get_bytes_inplace,
+ set_codepoints,
+ set_bytes,
+ become_encoding,
+ codepoints,
+ bytes
+ };
+ memcpy(return_encoding, &base_encoding, sizeof(ENCODING));
+ Parrot_register_encoding(interpreter, "fixed_8", return_encoding);
+ return return_encoding;
}
/*
1.31 +24 -24 parrot/include/parrot/encoding.h
Index: encoding.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/encoding.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- encoding.h 27 Feb 2005 09:58:43 -0000 1.30
+++ encoding.h 27 Feb 2005 12:12:28 -0000 1.31
@@no-spam -1,7 +1,7 @@no-spam
/* encoding.h
* Copyright: 2004 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: encoding.h,v 1.30 2005/02/27 09:58:43 leo Exp $
+ * $Id: encoding.h,v 1.31 2005/02/27 12:12:28 leo Exp $
* Overview:
* This is the header for the generic encoding functions
* Data Structure and Algorithms:
@@no-spam -15,21 +15,21 @@no-spam
#include "parrot/parrot.h"
-typedef void (*encoding_to_encoding_t)(Interp* interpreter, STRING *string);
-typedef STRING *(*encoding_copy_to_encoding_t)(Interp* interpreter, STRING *string);
-typedef UINTVAL (*encoding_get_codepoint_t)(Interp* interpreter, const STRING *source_string, UINTVAL offset);
-typedef void (*encoding_set_codepoint_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL codepoint);
-typedef UINTVAL (*encoding_get_byte_t)(Interp* interpreter, const STRING *source_string, UINTVAL offset);
-typedef void (*encoding_set_byte_t)(Interp* interpreter, const STRING *source_string, UINTVAL offset, UINTVAL count);
-typedef STRING *(*encoding_get_codepoints_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL count);
-typedef STRING *(*encoding_get_bytes_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL count);
-typedef STRING *(*encoding_get_codepoints_inplace_t)(Interp* interpreter, STRING *source_string, STRING *dest_string, UINTVAL offset, UINTVAL count);
-typedef STRING *(*encoding_get_bytes_inplace_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *dest_string);
-typedef void (*encoding_set_codepoints_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_bytes);
-typedef void (*encoding_set_bytes_t)(Interp* interpreter, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_bytes);
-typedef void (*encoding_become_encoding_t)(Interp* interpreter, STRING *source_string);
-typedef UINTVAL (*encoding_codepoints_t)(Interp* interpreter, STRING *source_string);
-typedef UINTVAL (*encoding_bytes_t)(Interp* interpreter, STRING *source_string);
+typedef void (*encoding_to_encoding_t)(Interp*, STRING *string);
+typedef STRING *(*encoding_copy_to_encoding_t)(Interp*, STRING *string);
+typedef UINTVAL (*encoding_get_codepoint_t)(Interp*, const STRING *source_string, UINTVAL offset);
+typedef void (*encoding_set_codepoint_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL codepoint);
+typedef UINTVAL (*encoding_get_byte_t)(Interp*, const STRING *source_string, UINTVAL offset);
+typedef void (*encoding_set_byte_t)(Interp*, const STRING *source_string, UINTVAL offset, UINTVAL count);
+typedef STRING *(*encoding_get_codepoints_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL count);
+typedef STRING *(*encoding_get_bytes_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL count);
+typedef STRING *(*encoding_get_codepoints_inplace_t)(Interp*, STRING *source_string, STRING *dest_string, UINTVAL offset, UINTVAL count);
+typedef STRING *(*encoding_get_bytes_inplace_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *dest_string);
+typedef void (*encoding_set_codepoints_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_bytes);
+typedef void (*encoding_set_bytes_t)(Interp*, STRING *source_string, UINTVAL offset, UINTVAL count, STRING *new_bytes);
+typedef void (*encoding_become_encoding_t)(Interp*, STRING *source_string);
+typedef UINTVAL (*encoding_codepoints_t)(Interp*, STRING *source_string);
+typedef UINTVAL (*encoding_bytes_t)(Interp*, STRING *source_string);
struct _encoding {
const char *name;
@@no-spam -61,14 +61,14 @@no-spam
#define PARROT_FIXED_8_ENCODING Parrot_fixed_8_encoding_ptr
#define PARROT_DEFAULT_FOR_UNICODE_ENCODING NULL
-ENCODING *Parrot_new_encoding(Interp* interpreter);
-ENCODING *Parrot_load_encoding(Interp* interpreter, const char *encoding_name);
-ENCODING *Parrot_find_encoding(Interp *interpreter, const char *encodingname);
-INTVAL Parrot_register_encoding(Interp *interpreter, const char *encodingname, ENCODING *encoding);
-INTVAL Parrot_make_default_encoding(Interp *interpreter, const char *encodingname, ENCODING *encoding);
-ENCODING *Parrot_default_encoding(Interp *interpreter);
-typedef INTVAL (*encoding_converter_t)(Interp *interpreter, ENCODING *lhs, ENCODING *rhs);
-encoding_converter_t Parrot_find_encoding_converter(Interp *interpreter, ENCODING *lhs, ENCODING *rhs);
+ENCODING *Parrot_new_encoding(Interp*);
+ENCODING *Parrot_load_encoding(Interp*, const char *encoding_name);
+ENCODING *Parrot_find_encoding(Interp *, const char *encodingname);
+INTVAL Parrot_register_encoding(Interp *, const char *encodingname, ENCODING *encoding);
+INTVAL Parrot_make_default_encoding(Interp *, const char *encodingname, ENCODING *encoding);
+ENCODING *Parrot_default_encoding(Interp *);
+typedef INTVAL (*encoding_converter_t)(Interp *, ENCODING *lhs, ENCODING *rhs);
+encoding_converter_t Parrot_find_encoding_converter(Interp *, ENCODING *lhs, ENCODING *rhs);
#define ENCODING_MAX_BYTES_PER_CODEPOINT(interp, source) ((ENCODING *)source->encoding)->max_bytes_per_codepoint
1.23 +26 -9 parrot/src/encoding.c
Index: encoding.c
===================================================================
RCS file: /cvs/public/parrot/src/encoding.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- encoding.c 27 Feb 2005 09:58:47 -0000 1.22
+++ encoding.c 27 Feb 2005 12:12:29 -0000 1.23
@@no-spam -1,6 +1,6 @@no-spam
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: encoding.c,v 1.22 2005/02/27 09:58:47 leo Exp $
+$Id: encoding.c,v 1.23 2005/02/27 12:12:29 leo Exp $
=head1 NAME
@@no-spam -22,23 +22,32 @@no-spam
encodings and such for strings if we can't be sure we've got enough
info set up to actually build strings... */
-ENCODING *Parrot_new_encoding(Interp *interpreter) {
- return mem_sys_allocate(sizeof(ENCODING));
+ENCODING *
+Parrot_new_encoding(Interp *interpreter)
+{
+ return mem_sys_allocate(sizeof(ENCODING));
}
-ENCODING *Parrot_find_encoding(Interp *interpreter, const char *encodingname) {
+ENCODING *
+Parrot_find_encoding(Interp *interpreter, const char *encodingname)
+{
if (!strcmp("fixed_8", encodingname)) {
return Parrot_fixed_8_encoding_ptr;
}
return NULL;
}
-ENCODING *Parrot_load_encoding(Interp *interpreter, const char *encodingname) {
+ENCODING *
+Parrot_load_encoding(Interp *interpreter, const char *encodingname)
+{
internal_exception(UNIMPLEMENTED, "Can't load encodings yet");
return NULL;
}
-INTVAL Parrot_register_encoding(Interp *interpreter, const char *encodingname, ENCODING *encoding) {
+INTVAL
+Parrot_register_encoding(Interp *interpreter, const char *encodingname,
+ ENCODING *encoding)
+{
if (!strcmp("fixed_8", encodingname)) {
Parrot_fixed_8_encoding_ptr = encoding;
if (!Parrot_default_encoding_ptr) {
@@no-spam -50,16 +59,24 @@no-spam
return 0;
}
-INTVAL Parrot_make_default_encoding(Interp *interpreter, const char *encodingname, ENCODING *encoding) {
+INTVAL
+Parrot_make_default_encoding(Interp *interpreter, const char *encodingname,
+ ENCODING *encoding)
+{
Parrot_default_encoding_ptr = encoding;
return 1;
}
-ENCODING *Parrot_default_encoding(Interp *interpreter) {
+ENCODING *
+Parrot_default_encoding(Interp *interpreter)
+{
return Parrot_default_encoding_ptr;
}
-encoding_converter_t Parrot_find_encoding_converter(Interp *interpreter, ENCODING *lhs, ENCODING *rhs) {
+encoding_converter_t
+Parrot_find_encoding_converter(Interp *interpreter, ENCODING *lhs,
+ ENCODING *rhs)
+{
return NULL;
}