mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 20:22:00 +00:00
Bug 893222 - Part 1: Add a new PutEscapedString implementation, which takes a raw jschar*. r=njn
This commit is contained in:
parent
37aab28fe2
commit
3d26462c81
@ -4403,6 +4403,14 @@ js_OneUcs4ToUtf8Char(uint8_t *utf8Buffer, uint32_t ucs4Char)
|
||||
size_t
|
||||
js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, JSLinearString *str,
|
||||
uint32_t quote)
|
||||
{
|
||||
return PutEscapedStringImpl(buffer, bufferSize, fp, str->chars(),
|
||||
str->length(), quote);
|
||||
}
|
||||
|
||||
size_t
|
||||
js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, const jschar *chars,
|
||||
size_t length, uint32_t quote)
|
||||
{
|
||||
enum {
|
||||
STOP, FIRST_QUOTE, LAST_QUOTE, CHARS, ESCAPE_START, ESCAPE_MORE
|
||||
@ -4417,8 +4425,7 @@ js::PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, JSLinearStri
|
||||
else
|
||||
bufferSize--;
|
||||
|
||||
const jschar *chars = str->chars();
|
||||
const jschar *charsEnd = chars + str->length();
|
||||
const jschar *charsEnd = chars + length;
|
||||
size_t n = 0;
|
||||
state = FIRST_QUOTE;
|
||||
unsigned shift = 0;
|
||||
|
@ -320,6 +320,10 @@ namespace js {
|
||||
extern size_t
|
||||
PutEscapedStringImpl(char *buffer, size_t size, FILE *fp, JSLinearString *str, uint32_t quote);
|
||||
|
||||
extern size_t
|
||||
PutEscapedStringImpl(char *buffer, size_t bufferSize, FILE *fp, const jschar *chars,
|
||||
size_t length, uint32_t quote);
|
||||
|
||||
/*
|
||||
* Write str into buffer escaping any non-printable or non-ASCII character
|
||||
* using \escapes for JS string literals.
|
||||
@ -339,6 +343,16 @@ PutEscapedString(char *buffer, size_t size, JSLinearString *str, uint32_t quote)
|
||||
return n;
|
||||
}
|
||||
|
||||
inline size_t
|
||||
PutEscapedString(char *buffer, size_t bufferSize, const jschar *chars, size_t length, uint32_t quote)
|
||||
{
|
||||
size_t n = PutEscapedStringImpl(buffer, bufferSize, NULL, chars, length, quote);
|
||||
|
||||
/* PutEscapedStringImpl can only fail with a file. */
|
||||
JS_ASSERT(n != size_t(-1));
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write str into file escaping any non-printable or non-ASCII character.
|
||||
* If quote is not 0, it must be a single or double quote character that
|
||||
|
Loading…
x
Reference in New Issue
Block a user