Commit 53530189 authored by kenton@google.com's avatar kenton@google.com

Address comments from various code reviews.

parent 2429e3a0
...@@ -704,7 +704,13 @@ public final class TextFormat { ...@@ -704,7 +704,13 @@ public final class TextFormat {
return ByteString.copyFrom(list); return ByteString.copyFrom(list);
} }
public void consumeByteString(List<ByteString> list) throws ParseException { /**
* Like {@link #consumeByteString()} but adds each token of the string to
* the given list. String literals (whether bytes or text) may come in
* multiple adjacent tokens which are automatically concatenated, like in
* C or Python.
*/
private void consumeByteString(List<ByteString> list) throws ParseException {
final char quote = currentToken.length() > 0 ? currentToken.charAt(0) final char quote = currentToken.length() > 0 ? currentToken.charAt(0)
: '\0'; : '\0';
if (quote != '\"' && quote != '\'') { if (quote != '\"' && quote != '\'') {
......
...@@ -536,12 +536,18 @@ class _Tokenizer(object): ...@@ -536,12 +536,18 @@ class _Tokenizer(object):
Raises: Raises:
ParseError: If a byte array value couldn't be consumed. ParseError: If a byte array value couldn't be consumed.
""" """
list = [self.ConsumeSingleByteString()] list = [self._ConsumeSingleByteString()]
while len(self.token) > 0 and self.token[0] in ('\'', '"'): while len(self.token) > 0 and self.token[0] in ('\'', '"'):
list.append(self.ConsumeSingleByteString()) list.append(self._ConsumeSingleByteString())
return "".join(list) return "".join(list)
def ConsumeSingleByteString(self): def _ConsumeSingleByteString(self):
"""Consume one token of a string literal.
String literals (whether bytes or text) can come in multiple adjacent
tokens which are automatically concatenated, like in C or Python. This
method only consumes one token.
"""
text = self.token text = self.token
if len(text) < 1 or text[0] not in ('\'', '"'): if len(text) < 1 or text[0] not in ('\'', '"'):
raise self._ParseError('Exptected string.') raise self._ParseError('Exptected string.')
......
...@@ -219,14 +219,23 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector, ...@@ -219,14 +219,23 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// An OutputDirectory implementation that writes to disk. // An OutputDirectory implementation that buffers files in memory, then dumps
// them all to disk on demand.
class CommandLineInterface::MemoryOutputDirectory : public OutputDirectory { class CommandLineInterface::MemoryOutputDirectory : public OutputDirectory {
public: public:
MemoryOutputDirectory(); MemoryOutputDirectory();
~MemoryOutputDirectory(); ~MemoryOutputDirectory();
// Write all files in the directory to disk at the given output location,
// which must end in a '/'.
bool WriteAllToDisk(const string& prefix); bool WriteAllToDisk(const string& prefix);
// Write the contents of this directory to a ZIP-format archive with the
// given name.
bool WriteAllToZip(const string& filename); bool WriteAllToZip(const string& filename);
// Add a boilerplate META-INF/MANIFEST.MF file as required by the Java JAR
// format, unless one has already been written.
void AddJarManifest(); void AddJarManifest();
// implements OutputDirectory -------------------------------------- // implements OutputDirectory --------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment