[svn:parrot] r46375 - branches/codestring/src/pmc
coke at svn.parrot.org
coke at svn.parrot.org
Fri May 7 02:02:47 UTC 2010
Author: coke
Date: Fri May 7 02:02:46 2010
New Revision: 46375
URL: https://trac.parrot.org/parrot/changeset/46375
Log:
whitespace & other clenaup
Modified:
branches/codestring/src/pmc/codestring.pmc
Modified: branches/codestring/src/pmc/codestring.pmc
==============================================================================
--- branches/codestring/src/pmc/codestring.pmc Fri May 7 01:38:49 2010 (r46374)
+++ branches/codestring/src/pmc/codestring.pmc Fri May 7 02:02:46 2010 (r46375)
@@ -105,87 +105,87 @@
*/
- METHOD emit(STRING *fmt, PMC *args :slurpy, PMC *hash :slurpy :named) {
- STRING * const percent = CONST_STRING(INTERP, "%");
- STRING * const comma = CONST_STRING(INTERP, ",");
- STRING * const comma_space = CONST_STRING(INTERP, ", ");
- STRING * const newline = CONST_STRING(INTERP, "\n");
- STRING *key;
- PMC *stringbuilder;
- INTVAL percentPos;
- INTVAL pos = 0;
-
- GET_ATTR_stringbuilder(INTERP, SELF, stringbuilder);
-
- /* Loop over the format string, splitting it into chunks
- * for the string builder. */
- while (pos >= 0) {
- /* Find the next % */
- percentPos = Parrot_str_find_index(INTERP, fmt, percent, pos);
-
- if (percentPos < 0) {
- if (pos == 0) {
- VTABLE_push_string(INTERP, stringbuilder, fmt);
+ METHOD emit(STRING *fmt, PMC *args :slurpy, PMC *hash :slurpy :named) {
+ STRING * const percent = CONST_STRING(INTERP, "%");
+ STRING * const comma = CONST_STRING(INTERP, ",");
+ STRING * const comma_space = CONST_STRING(INTERP, ", ");
+ STRING * const newline = CONST_STRING(INTERP, "\n");
+ STRING *key;
+ PMC *stringbuilder;
+ INTVAL percentPos;
+ INTVAL pos = 0;
+
+ GET_ATTR_stringbuilder(INTERP, SELF, stringbuilder);
+
+ /* Loop over the format string, splitting it into chunks
+ * for the string builder. */
+ while (pos >= 0) {
+ /* Find the next % */
+ percentPos = Parrot_str_find_index(INTERP, fmt, percent, pos);
+
+ if (percentPos < 0) {
+ if (pos == 0) {
+ VTABLE_push_string(INTERP, stringbuilder, fmt);
+ }
+ else {
+ /* remaining string can be added as is. */
+ VTABLE_push_string(INTERP, stringbuilder,
+ Parrot_str_substr(INTERP, fmt, pos,
+ Parrot_str_byte_length(INTERP, fmt) -pos));
+ }
+ break;
}
else {
- /* remaining string can be added as is. */
+ /* slurp up to just before the % sign... */
VTABLE_push_string(INTERP, stringbuilder,
- Parrot_str_substr(INTERP, fmt, pos,
- Parrot_str_byte_length(INTERP, fmt) -pos));
- }
- break;
- }
- else {
- /* slurp up to just before the % sign... */
- VTABLE_push_string(INTERP, stringbuilder,
- Parrot_str_substr(INTERP, fmt, pos, percentPos - pos));
- /* skip the % sign */
- pos = percentPos + 1 ;
- }
+ Parrot_str_substr(INTERP, fmt, pos, percentPos - pos));
+ /* skip the % sign */
+ pos = percentPos + 1 ;
+ }
- /* key is always a single character */
- key = Parrot_str_substr(INTERP, fmt, pos++, 1);
+ /* key is always a single character */
+ key = Parrot_str_substr(INTERP, fmt, pos++, 1);
- if (VTABLE_exists_keyed_str(INTERP, hash, key)) {
- VTABLE_push_string(INTERP, stringbuilder,
- VTABLE_get_string_keyed_str(INTERP, hash, key));
- }
- else if (Parrot_str_is_cclass(INTERP, enum_cclass_numeric, key, 0)) {
- VTABLE_push_string(INTERP, stringbuilder,
- VTABLE_get_string_keyed_int(INTERP, args,
- Parrot_str_to_int(INTERP, key)));
- }
- else if (Parrot_str_equal(INTERP, key, comma)) {
- INTVAL num_args = VTABLE_elements(INTERP, args);
- INTVAL pos_args = 1;
+ if (VTABLE_exists_keyed_str(INTERP, hash, key)) {
+ VTABLE_push_string(INTERP, stringbuilder,
+ VTABLE_get_string_keyed_str(INTERP, hash, key));
+ }
+ else if (Parrot_str_is_cclass(INTERP, enum_cclass_numeric, key, 0)) {
+ VTABLE_push_string(INTERP, stringbuilder,
+ VTABLE_get_string_keyed_int(INTERP, args,
+ Parrot_str_to_int(INTERP, key)));
+ }
+ else if (Parrot_str_equal(INTERP, key, comma)) {
+ INTVAL num_args = VTABLE_elements(INTERP, args);
+ INTVAL pos_args = 1;
- VTABLE_push_string(INTERP, stringbuilder,
- VTABLE_get_string_keyed_int(INTERP, args, 0));
+ VTABLE_push_string(INTERP, stringbuilder,
+ VTABLE_get_string_keyed_int(INTERP, args, 0));
- while (pos_args < num_args) {
- VTABLE_push_string(INTERP, stringbuilder, comma_space);
+ while (pos_args < num_args) {
+ VTABLE_push_string(INTERP, stringbuilder, comma_space);
+ VTABLE_push_string(INTERP, stringbuilder,
+ VTABLE_get_string_keyed_int(INTERP, args, pos_args));
+ pos_args++;
+ }
+ }
+ else if (Parrot_str_equal(INTERP, key, percent)) {
+ VTABLE_push_string(INTERP, stringbuilder, percent);
+ }
+ else {
+ /* %foo has no special meaning, pass it through unchanged */
VTABLE_push_string(INTERP, stringbuilder,
- VTABLE_get_string_keyed_int(INTERP, args, pos_args));
- pos_args++;
+ Parrot_str_substr(INTERP, fmt, pos-2, 2));
}
}
- else if (Parrot_str_equal(INTERP, key, percent)) {
- VTABLE_push_string(INTERP, stringbuilder, percent);
- }
- else {
- /* %foo has no special meaning, pass it through unchanged */
- VTABLE_push_string(INTERP, stringbuilder,
- Parrot_str_substr(INTERP, fmt, pos-2, 2));
- }
- }
- /* Add a newline if necessary */
- if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(INTERP, fmt) - 1))
- VTABLE_push_string(INTERP, stringbuilder, newline);
+ /* Add a newline if necessary */
+ if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(INTERP, fmt) - 1))
+ VTABLE_push_string(INTERP, stringbuilder, newline);
- RETURN(PMC *SELF);
-}
+ RETURN(PMC *SELF);
+ }
/*
@@ -236,56 +236,56 @@
*/
- METHOD lineof(INTVAL pos) {
- PMC *linepos;
- INTVAL count;
- INTVAL line = 0;
-
- GET_ATTR_linepos(INTERP, SELF, linepos);
-
- /* build the linepos array if we haven't already done so */
- if (!linepos || PMC_IS_NULL(linepos)) {
- STRING *str = NULL;
- INTVAL eos;
- INTVAL jpos;
-
- linepos = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
- /* get the string itself */
- str = SELF.get_string();
- eos = Parrot_str_byte_length(INTERP, str);
- /* find the first newline, if any */
- jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline,
- str, 0, eos);
- while (jpos < eos) {
- jpos++;
- /* add the start of line position */
- VTABLE_push_integer(INTERP, linepos, jpos);
-
- /* treat \r\n as a single newline */
- if (jpos < eos
- && string_ord(INTERP, str, jpos - 1) == 13
- && string_ord(INTERP, str, jpos) == 10) {
+ METHOD lineof(INTVAL pos) {
+ PMC *linepos;
+ INTVAL count;
+ INTVAL line = 0;
+
+ GET_ATTR_linepos(INTERP, SELF, linepos);
+
+ /* build the linepos array if we haven't already done so */
+ if (!linepos || PMC_IS_NULL(linepos)) {
+ STRING *str = NULL;
+ INTVAL eos;
+ INTVAL jpos;
+
+ linepos = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
+ /* get the string itself */
+ str = SELF.get_string();
+ eos = Parrot_str_byte_length(INTERP, str);
+ /* find the first newline, if any */
+ jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline,
+ str, 0, eos);
+ while (jpos < eos) {
jpos++;
+ /* add the start of line position */
+ VTABLE_push_integer(INTERP, linepos, jpos);
+
+ /* treat \r\n as a single newline */
+ if (jpos < eos
+ && string_ord(INTERP, str, jpos - 1) == 13
+ && string_ord(INTERP, str, jpos) == 10) {
+ jpos++;
+ }
+ /* search for the next newline */
+ jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline,
+ str, jpos, eos);
}
- /* search for the next newline */
- jpos = Parrot_str_find_cclass(INTERP, enum_cclass_newline,
- str, jpos, eos);
+ /* save the array of line positions */
+ SET_ATTR_linepos(INTERP, SELF, linepos);
}
- /* save the array of line positions */
- SET_ATTR_linepos(INTERP, SELF, linepos);
- }
- /* Find the line from the array, stop at the first index that is
- * greater than the position we're looking for. We do a linear
- * search for now, * perhaps a binary search would be better someday.
- */
- count = VTABLE_elements(INTERP, linepos);
- while (line < count
- && VTABLE_get_integer_keyed_int(INTERP, linepos, line) <= pos)
- line++;
-
- RETURN(INTVAL line);
- }
+ /* Find the line from the array, stop at the first index that is
+ * greater than the position we're looking for. We do a linear
+ * search for now, * perhaps a binary search would be better someday.
+ */
+ count = VTABLE_elements(INTERP, linepos);
+ while (line < count
+ && VTABLE_get_integer_keyed_int(INTERP, linepos, line) <= pos)
+ line++;
+
+ RETURN(INTVAL line);
+ }
/*
@@ -302,21 +302,21 @@
*/
- METHOD unique(STRING *format :optional, int has_fmt :opt_flag) {
- static INTVAL counter = 10;
- STRING * const counter_as_string = Parrot_str_from_int(INTERP, counter);
- UNUSED(SELF);
+ METHOD unique(STRING *format :optional, int has_fmt :opt_flag) {
+ static INTVAL counter = 10;
+ STRING * const counter_as_string = Parrot_str_from_int(INTERP, counter);
+ UNUSED(SELF);
- counter++;
+ counter++;
- if (!has_fmt) {
- RETURN(STRING *counter_as_string);
- }
- else {
- STRING *result = Parrot_str_concat(INTERP, format, counter_as_string);
- RETURN(STRING *result);
+ if (!has_fmt) {
+ RETURN(STRING *counter_as_string);
+ }
+ else {
+ STRING *result = Parrot_str_concat(INTERP, format, counter_as_string);
+ RETURN(STRING *result);
+ }
}
- }
/*
@@ -330,35 +330,35 @@
*/
- METHOD escape(STRING *str) {
- STRING *escaped_str = Parrot_str_escape(INTERP, str);
- STRING * const quote = CONST_STRING(INTERP, "\x22");
- STRING * const x = CONST_STRING(INTERP, "\\x");
- INTVAL x_pos;
- INTVAL is_unicode = 0;
- UNUSED(SELF);
-
- escaped_str = Parrot_str_concat(INTERP, quote, escaped_str);
- escaped_str = Parrot_str_concat(INTERP, escaped_str, quote);
- x_pos = Parrot_str_find_index(INTERP, escaped_str, x, 0);
+ METHOD escape(STRING *str) {
+ STRING *escaped_str = Parrot_str_escape(INTERP, str);
+ STRING * const quote = CONST_STRING(INTERP, "\x22");
+ STRING * const x = CONST_STRING(INTERP, "\\x");
+ INTVAL x_pos;
+ INTVAL is_unicode = 0;
+ UNUSED(SELF);
+
+ escaped_str = Parrot_str_concat(INTERP, quote, escaped_str);
+ escaped_str = Parrot_str_concat(INTERP, escaped_str, quote);
+ x_pos = Parrot_str_find_index(INTERP, escaped_str, x, 0);
- if (x_pos != -1) {
- is_unicode = 1;
- }
- else {
- STRING * const u = CONST_STRING(INTERP, "\\u");
- const INTVAL u_pos = Parrot_str_find_index(INTERP, escaped_str, u, 0);
- if (u_pos != -1)
+ if (x_pos != -1) {
is_unicode = 1;
- }
+ }
+ else {
+ STRING * const u = CONST_STRING(INTERP, "\\u");
+ const INTVAL u_pos = Parrot_str_find_index(INTERP, escaped_str, u, 0);
+ if (u_pos != -1)
+ is_unicode = 1;
+ }
- if (is_unicode) {
- STRING * const unicode = CONST_STRING(INTERP, "unicode:");
- escaped_str = Parrot_str_concat(INTERP, unicode, escaped_str);
- }
+ if (is_unicode) {
+ STRING * const unicode = CONST_STRING(INTERP, "unicode:");
+ escaped_str = Parrot_str_concat(INTERP, unicode, escaped_str);
+ }
- RETURN(STRING *escaped_str);
- }
+ RETURN(STRING *escaped_str);
+ }
/*
@@ -372,21 +372,21 @@
*/
- METHOD charname_to_ord(STRING *name) {
+ METHOD charname_to_ord(STRING *name) {
#if PARROT_HAS_ICU
- UErrorCode err = U_ZERO_ERROR;
- char * const cstr = Parrot_str_to_cstring(INTERP, name);
- UChar32 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err);
- Parrot_str_free_cstring(cstr);
- if (U_SUCCESS(err)) {
- RETURN(INTVAL codepoint);
- }
- RETURN(INTVAL -1);
+ UErrorCode err = U_ZERO_ERROR;
+ char * const cstr = Parrot_str_to_cstring(INTERP, name);
+ UChar32 codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err);
+ Parrot_str_free_cstring(cstr);
+ if (U_SUCCESS(err))
+ RETURN(INTVAL codepoint);
+ else
+ RETURN(INTVAL -1);
#else
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_LIBRARY_ERROR,
- "no ICU lib loaded");
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_LIBRARY_ERROR,
+ "no ICU lib loaded");
#endif
- }
+ }
/*
@@ -399,26 +399,35 @@
*/
- METHOD key(PMC *args :slurpy) {
- INTVAL index;
- const INTVAL elements = VTABLE_elements(INTERP, args);
- STRING * const open_bracket = CONST_STRING(INTERP, "[");
- STRING * const semi = CONST_STRING(INTERP, ";");
- STRING * const close_bracket = CONST_STRING(INTERP, "]");
- STRING * const s_array = CONST_STRING(INTERP, "array");
- STRING * prefix = NULL;
- STRING * out = open_bracket;
-
- for (index = 0; index < elements; index++) {
- PMC * const P0 = VTABLE_get_pmc_keyed_int(INTERP, args, index);
-
- if (!PMC_IS_NULL(P0)) {
- if (VTABLE_does(INTERP, P0, s_array)) {
- const INTVAL elements2 = VTABLE_elements(INTERP, P0);
- INTVAL index2;
-
- for (index2 = 0; index2 < elements2; index2++) {
- STRING *S0 = VTABLE_get_string_keyed_int(INTERP, P0, index2);
+ METHOD key(PMC *args :slurpy) {
+ INTVAL index;
+ const INTVAL elements = VTABLE_elements(INTERP, args);
+ STRING * const open_bracket = CONST_STRING(INTERP, "[");
+ STRING * const semi = CONST_STRING(INTERP, ";");
+ STRING * const close_bracket = CONST_STRING(INTERP, "]");
+ STRING * const s_array = CONST_STRING(INTERP, "array");
+ STRING * prefix = NULL;
+ STRING * out = open_bracket;
+
+ for (index = 0; index < elements; index++) {
+ PMC * const P0 = VTABLE_get_pmc_keyed_int(INTERP, args, index);
+
+ if (!PMC_IS_NULL(P0)) {
+ if (VTABLE_does(INTERP, P0, s_array)) {
+ const INTVAL elements2 = VTABLE_elements(INTERP, P0);
+ INTVAL index2;
+
+ for (index2 = 0; index2 < elements2; index2++) {
+ STRING *S0 = VTABLE_get_string_keyed_int(INTERP, P0, index2);
+ (STRING *S0) = PCCINVOKE(INTERP, SELF, "escape", STRING *S0);
+ if (prefix)
+ out = Parrot_str_concat(INTERP, out, prefix);
+ out = Parrot_str_concat(INTERP, out, S0);
+ prefix = semi;
+ }
+ }
+ else {
+ STRING *S0 = VTABLE_get_string_keyed_int(INTERP, args, index);
(STRING *S0) = PCCINVOKE(INTERP, SELF, "escape", STRING *S0);
if (prefix)
out = Parrot_str_concat(INTERP, out, prefix);
@@ -426,21 +435,12 @@
prefix = semi;
}
}
- else {
- STRING *S0 = VTABLE_get_string_keyed_int(INTERP, args, index);
- (STRING *S0) = PCCINVOKE(INTERP, SELF, "escape", STRING *S0);
- if (prefix)
- out = Parrot_str_concat(INTERP, out, prefix);
- out = Parrot_str_concat(INTERP, out, S0);
- prefix = semi;
- }
}
- }
- out = Parrot_str_concat(INTERP, out, close_bracket);
+ out = Parrot_str_concat(INTERP, out, close_bracket);
- RETURN(STRING *out);
-}
+ RETURN(STRING *out);
+ }
VTABLE void i_concatenate_str(STRING *value) {
PMC *stringbuilder;
@@ -466,7 +466,6 @@
}
-
/*
* Local variables:
* c-file-style: "parrot"
More information about the parrot-commits
mailing list