}
if (c == '(')
{
- struct mixed_string_buffer *bp;
+ struct mixed_string_buffer msb;
/* The state is either 0 or
N, after a ')' and N-1 bytes of the delimiter have been
encountered. */
/* Start accumulating the string. */
if (relevant)
- bp = mixed_string_buffer_alloc (lc_string,
- logical_file_name,
- line_number);
- else
- bp = NULL;
+ mixed_string_buffer_init (&msb, lc_string,
+ logical_file_name,
+ line_number);
state = 0;
for (;;)
/* Keep line_number in sync. */
if (relevant)
- bp->line_number = line_number;
+ msb.line_number = line_number;
if (c == EOF)
break;
if (relevant)
{
tp->type = token_type_string_literal;
- tp->string = mixed_string_buffer_done (bp);
+ tp->string = mixed_string_buffer_result (&msb);
tp->comment = add_reference (savable_comment);
}
else
can be ')'. */
if (relevant)
for (i = 0; i < state; i++)
- mixed_string_buffer_append_char (bp, buffer[i]);
+ mixed_string_buffer_append_char (&msb, buffer[i]);
/* But c may be ')'. */
if (c == ')')
else
{
if (relevant)
- mixed_string_buffer_append_char (bp, c);
+ mixed_string_buffer_append_char (&msb, c);
state = 0;
}
}
about the argument not matching the prototype. Just pretend it
won't happen. */
{
- struct mixed_string_buffer *bp;
+ struct mixed_string_buffer msb;
/* Start accumulating the string. */
- bp = mixed_string_buffer_alloc (lc_string,
- logical_file_name,
- line_number);
+ mixed_string_buffer_init (&msb, lc_string,
+ logical_file_name, line_number);
for (;;)
{
c = phase7_getc ();
/* Keep line_number in sync. */
- bp->line_number = line_number;
+ msb.line_number = line_number;
if (c == P7_NEWLINE)
{
{
assert (UNICODE_VALUE (c) >= 0
&& UNICODE_VALUE (c) < 0x110000);
- mixed_string_buffer_append_unicode (bp,
- UNICODE_VALUE (c));
+ mixed_string_buffer_append_unicode (&msb, UNICODE_VALUE (c));
}
else
- mixed_string_buffer_append_char (bp, c);
+ mixed_string_buffer_append_char (&msb, c);
}
tp->type = token_type_string_literal;
- tp->string = mixed_string_buffer_done (bp);
+ tp->string = mixed_string_buffer_result (&msb);
tp->comment = add_reference (savable_comment);
return;
}
case '"':
/* Regular string literal. */
{
- struct mixed_string_buffer *literal;
+ struct mixed_string_buffer literal;
lexical_context = lc_string;
- literal = mixed_string_buffer_alloc (lexical_context,
- logical_file_name,
- logical_line_number);
- accumulate_escaped (literal, '"');
- tp->string = mixed_string_buffer_done (literal);
+ mixed_string_buffer_init (&literal,
+ lexical_context,
+ logical_file_name,
+ logical_line_number);
+ accumulate_escaped (&literal, '"');
+ tp->string = mixed_string_buffer_result (&literal);
tp->comment = add_reference (savable_comment);
lexical_context = lc_outside;
tp->type = token_type_string_literal;
return;
}
- /* Strings. */
+ case '"': case '\'':
+ /* Strings. */
{
- struct mixed_string_buffer *bp;
int quote_char;
+ struct mixed_string_buffer msb;
- case '"': case '\'':
- quote_char = c;
- lexical_context = lc_string;
- /* Start accumulating the string. */
- bp = mixed_string_buffer_alloc (lexical_context,
- logical_file_name,
- line_number);
- for (;;)
- {
- int uc = phase7_getuc (quote_char);
+ quote_char = c;
+ lexical_context = lc_string;
+ /* Start accumulating the string. */
+ mixed_string_buffer_init (&msb, lexical_context,
+ logical_file_name, line_number);
+ for (;;)
+ {
+ int uc = phase7_getuc (quote_char);
- /* Keep line_number in sync. */
- bp->line_number = line_number;
+ /* Keep line_number in sync. */
+ msb.line_number = line_number;
- if (uc == P7_EOF || uc == P7_STRING_END)
- break;
+ if (uc == P7_EOF || uc == P7_STRING_END)
+ break;
- if (IS_UNICODE (uc))
- {
- assert (UNICODE_VALUE (uc) >= 0
- && UNICODE_VALUE (uc) < 0x110000);
- mixed_string_buffer_append_unicode (bp,
- UNICODE_VALUE (uc));
- }
- else
- mixed_string_buffer_append_char (bp, uc);
- }
- tp->string = mixed_string_buffer_done (bp);
- tp->comment = add_reference (savable_comment);
- lexical_context = lc_outside;
- tp->type = last_token_type = token_type_string;
- return;
+ if (IS_UNICODE (uc))
+ {
+ assert (UNICODE_VALUE (uc) >= 0
+ && UNICODE_VALUE (uc) < 0x110000);
+ mixed_string_buffer_append_unicode (&msb,
+ UNICODE_VALUE (uc));
+ }
+ else
+ mixed_string_buffer_append_char (&msb, uc);
+ }
+ tp->string = mixed_string_buffer_result (&msb);
+ tp->comment = add_reference (savable_comment);
+ lexical_context = lc_outside;
+ tp->type = last_token_type = token_type_string;
+ return;
}
case '+':
/* Strings. */
{
- struct mixed_string_buffer *bp;
int quote_char;
bool interpret_ansic;
bool interpret_unicode;
phase2_ungetc (c1);
}
backslash_counter = 0;
- /* Start accumulating the string. */
- bp = mixed_string_buffer_alloc (lexical_context,
- logical_file_name,
- line_number);
- for (;;)
- {
- int uc = phase7_getuc (quote_char, triple, interpret_ansic,
- interpret_unicode, &backslash_counter);
+ {
+ struct mixed_string_buffer msb;
- /* Keep line_number in sync. */
- bp->line_number = line_number;
+ /* Start accumulating the string. */
+ mixed_string_buffer_init (&msb, lexical_context,
+ logical_file_name, line_number);
+ for (;;)
+ {
+ int uc = phase7_getuc (quote_char, triple, interpret_ansic,
+ interpret_unicode, &backslash_counter);
- if (uc == P7_EOF || uc == P7_STRING_END)
- break;
+ /* Keep line_number in sync. */
+ msb.line_number = line_number;
- if (IS_UNICODE (uc))
- {
- assert (UNICODE_VALUE (uc) >= 0
- && UNICODE_VALUE (uc) < 0x110000);
- mixed_string_buffer_append_unicode (bp,
- UNICODE_VALUE (uc));
- }
- else
- mixed_string_buffer_append_char (bp, uc);
- }
- tp->string = mixed_string_buffer_done (bp);
- tp->comment = add_reference (savable_comment);
- lexical_context = lc_outside;
- tp->type = token_type_string;
+ if (uc == P7_EOF || uc == P7_STRING_END)
+ break;
+
+ if (IS_UNICODE (uc))
+ {
+ assert (UNICODE_VALUE (uc) >= 0
+ && UNICODE_VALUE (uc) < 0x110000);
+ mixed_string_buffer_append_unicode (&msb,
+ UNICODE_VALUE (uc));
+ }
+ else
+ mixed_string_buffer_append_char (&msb, uc);
+ }
+ tp->string = mixed_string_buffer_result (&msb);
+ tp->comment = add_reference (savable_comment);
+ lexical_context = lc_outside;
+ tp->type = token_type_string;
+ }
return;
}
return (bufpos == 0 ? pr_none : pr_parsed);
}
-static struct mixed_string_buffer *stringbuf;
+static struct mixed_string_buffer stringbuf;
/* Parses a string. Returns it in stringbuf, in UTF-8 encoding.
Returns a parse_result. */
phase2_ungetc (c);
return pr_none;
}
- stringbuf = mixed_string_buffer_alloc (lc_string,
- logical_file_name,
- line_number);
+ mixed_string_buffer_init (&stringbuf, lc_string,
+ logical_file_name, line_number);
for (;;)
{
c = phase1_getc ();
/* Keep line_number in sync. */
- stringbuf->line_number = line_number;
+ stringbuf.line_number = line_number;
if (c == EOF || (c >= 0 && c < 0x20))
return pr_syntax;
if (c == '"')
else
return pr_syntax;
}
- mixed_string_buffer_append_unicode (stringbuf, n);
+ mixed_string_buffer_append_unicode (&stringbuf, n);
}
else
{
default:
return pr_syntax;
}
- mixed_string_buffer_append_char (stringbuf, c);
+ mixed_string_buffer_append_char (&stringbuf, c);
}
}
else
- mixed_string_buffer_append_char (stringbuf, c);
+ mixed_string_buffer_append_char (&stringbuf, c);
}
return pr_parsed;
}
char *s1;
if (parse_string () != pr_parsed)
goto invalid_json;
- s1 = mixed_string_buffer_done (stringbuf);
+ s1 = mixed_string_buffer_result (&stringbuf);
/* Parse a colon. */
c = phase2_getc ();
char *s2;
if (parse_string () != pr_parsed)
goto invalid_json;
- s2 = mixed_string_buffer_done (stringbuf);
+ s2 = mixed_string_buffer_result (&stringbuf);
/* Parse a colon. */
c = phase2_getc ();
goto invalid_rsj;
if (r == pr_syntax || location != NULL)
goto invalid_json;
- location = mixed_string_buffer_done (stringbuf);
+ location = mixed_string_buffer_result (&stringbuf);
}
else if (strcmp (s2, "sourcebytes") == 0)
{
goto invalid_rsj;
if (r == pr_syntax || msgid != NULL)
goto invalid_json;
- msgid = mixed_string_buffer_done (stringbuf);
+ msgid = mixed_string_buffer_result (&stringbuf);
}
else
goto invalid_rsj;
/* FALLTHROUGH */
case '"':
{
- struct mixed_string_buffer *bp;
+ struct mixed_string_buffer msb;
int c2 = phase1_getc ();
if (c2 == '"')
phase2_ungetc (c2);
/* Start accumulating the string. */
- bp = mixed_string_buffer_alloc (lc_string,
- logical_file_name,
- line_number);
+ mixed_string_buffer_init (&msb, lc_string,
+ logical_file_name, line_number);
if (verbatim)
for (;;)
{
c = phase1_getc ();
/* Keep line_number in sync. */
- bp->line_number = line_number;
+ msb.line_number = line_number;
if (c == '"')
{
}
if (c == EOF)
break;
- mixed_string_buffer_append_char (bp, c);
+ mixed_string_buffer_append_char (&msb, c);
}
else
for (;;)
c = phase7_getc ();
/* Keep line_number in sync. */
- bp->line_number = line_number;
+ msb.line_number = line_number;
if (c == P7_NEWLINE)
{
{
assert (UNICODE_VALUE (c) >= 0
&& UNICODE_VALUE (c) < 0x110000);
- mixed_string_buffer_append_unicode (bp,
+ mixed_string_buffer_append_unicode (&msb,
UNICODE_VALUE (c));
}
else
- mixed_string_buffer_append_char (bp, c);
+ mixed_string_buffer_append_char (&msb, c);
}
/* Done accumulating the string. */
tp->type = last_token_type =
template ? token_type_string_template : token_type_string_literal;
- tp->string = mixed_string_buffer_done (bp);
+ tp->string = mixed_string_buffer_result (&msb);
tp->comment = add_reference (savable_comment);
return;
}
bp->line_number = line_number;
}
-struct mixed_string_buffer *
-mixed_string_buffer_alloc (lexical_context_ty lcontext,
- const char *logical_file_name,
- int line_number)
-{
- struct mixed_string_buffer *bp = XMALLOC (struct mixed_string_buffer);
- mixed_string_buffer_init (bp, lcontext, logical_file_name, line_number);
- return bp;
-}
-
bool
mixed_string_buffer_is_empty (const struct mixed_string_buffer *bp)
{
/* Return it. */
return utf8_buffer;
}
-
-char *
-mixed_string_buffer_done (struct mixed_string_buffer *bp)
-{
- char *result = mixed_string_buffer_result (bp);
-
- /* Free also bp itself. */
- free (bp);
-
- return result;
-}
const char *logical_file_name,
int line_number);
-/* Creates a fresh mixed_string_buffer. */
-extern struct mixed_string_buffer *
- mixed_string_buffer_alloc (lexical_context_ty lcontext,
- const char *logical_file_name,
- int line_number);
-
/* Determines whether a mixed_string_buffer is still empty. */
extern bool mixed_string_buffer_is_empty (const struct mixed_string_buffer *bp);
and returns the accumulated string in UTF-8. */
extern char * mixed_string_buffer_result (struct mixed_string_buffer *bp);
-/* Frees mixed_string_buffer and returns the accumulated string in UTF-8. */
-extern char * mixed_string_buffer_done (struct mixed_string_buffer *bp);
-
#ifdef __cplusplus
}