本文整理汇总了C++中MemoryOutputStream::toUTF8方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryOutputStream::toUTF8方法的具体用法?C++ MemoryOutputStream::toUTF8怎么用?C++ MemoryOutputStream::toUTF8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryOutputStream
的用法示例。
在下文中一共展示了MemoryOutputStream::toUTF8方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFromStream
const var var::readFromStream (InputStream& input)
{
const int numBytes = input.readCompressedInt();
if (numBytes > 0)
{
switch (input.readByte())
{
case 1: return var (input.readInt());
case 2: return var (true);
case 3: return var (false);
case 4: return var (input.readDouble());
case 5:
{
MemoryOutputStream mo;
mo.writeFromInputStream (input, numBytes - 1);
return var (mo.toUTF8());
}
default: input.skipNextBytes (numBytes - 1); break;
}
}
return var::null;
}
示例2: findKeySigEvents
static void findKeySigEvents (MidiFile& midiFile, StringPairArray& midiMetadata)
{
MidiMessageSequence keySigEvents;
midiFile.findAllKeySigEvents (keySigEvents);
const int numKeySigEvents = keySigEvents.getNumEvents();
MemoryOutputStream keySigSequence;
for (int i = 0; i < numKeySigEvents; ++i)
{
const MidiMessage& message (keySigEvents.getEventPointer (i)->message);
const int key = jlimit (0, 14, message.getKeySignatureNumberOfSharpsOrFlats() + 7);
const bool isMajor = message.isKeySignatureMajorKey();
static const char* majorKeys[] = { "Cb", "Gb", "Db", "Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#" };
static const char* minorKeys[] = { "Ab", "Eb", "Bb", "F", "C", "G", "D", "A", "E", "B", "F#", "C#", "G#", "D#", "A#" };
String keySigString (isMajor ? majorKeys[key]
: minorKeys[key]);
if (! isMajor)
keySigString << 'm';
if (i == 0)
midiMetadata.set (CoreAudioFormat::keySig, keySigString);
if (numKeySigEvents > 1)
keySigSequence << keySigString << ',' << keySigEvents.getEventTime (i) << ';';
}
if (keySigSequence.getDataSize() > 0)
midiMetadata.set ("key signature sequence", keySigSequence.toUTF8());
}
示例3: findTimeSigEvents
static void findTimeSigEvents (MidiFile& midiFile, StringPairArray& midiMetadata)
{
MidiMessageSequence timeSigEvents;
midiFile.findAllTimeSigEvents (timeSigEvents);
const int numTimeSigEvents = timeSigEvents.getNumEvents();
MemoryOutputStream timeSigSequence;
for (int i = 0; i < numTimeSigEvents; ++i)
{
int numerator, denominator;
timeSigEvents.getEventPointer(i)->message.getTimeSignatureInfo (numerator, denominator);
String timeSigString;
timeSigString << numerator << '/' << denominator;
if (i == 0)
midiMetadata.set (CoreAudioFormat::timeSig, timeSigString);
if (numTimeSigEvents > 1)
timeSigSequence << timeSigString << ',' << timeSigEvents.getEventTime (i) << ';';
}
if (timeSigSequence.getDataSize() > 0)
midiMetadata.set ("time signature sequence", timeSigSequence.toUTF8());
}
示例4: findTempoEvents
static void findTempoEvents (MidiFile& midiFile, StringPairArray& midiMetadata)
{
MidiMessageSequence tempoEvents;
midiFile.findAllTempoEvents (tempoEvents);
const int numTempoEvents = tempoEvents.getNumEvents();
MemoryOutputStream tempoSequence;
for (int i = 0; i < numTempoEvents; ++i)
{
const double tempo = getTempoFromTempoMetaEvent (tempoEvents.getEventPointer (i));
if (tempo > 0.0)
{
if (i == 0)
midiMetadata.set (CoreAudioFormat::tempo, String (tempo));
if (numTempoEvents > 1)
tempoSequence << String (tempo) << ',' << tempoEvents.getEventTime (i) << ';';
}
}
if (tempoSequence.getDataSize() > 0)
midiMetadata.set ("tempo sequence", tempoSequence.toUTF8());
}
示例5: parseString
static Result parseString (const juce_wchar quoteChar, String::CharPointerType& t, var& result)
{
MemoryOutputStream buffer (256);
for (;;)
{
juce_wchar c = t.getAndAdvance();
if (c == quoteChar)
break;
if (c == '\\')
{
c = t.getAndAdvance();
switch (c)
{
case '"':
case '\'':
case '\\':
case '/': break;
case 'a': c = '\a'; break;
case 'b': c = '\b'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'u':
{
c = 0;
for (int i = 4; --i >= 0;)
{
const int digitValue = CharacterFunctions::getHexDigitValue (t.getAndAdvance());
if (digitValue < 0)
return createFail ("Syntax error in unicode escape sequence");
c = (juce_wchar) ((c << 4) + digitValue);
}
break;
}
}
}
if (c == 0)
return createFail ("Unexpected end-of-input in string constant");
buffer.appendUTF8Char (c);
}
result = buffer.toUTF8();
return Result::ok();
}
示例6: readFromStream
var var::readFromStream (InputStream& input)
{
const int numBytes = input.readCompressedInt();
if (numBytes > 0)
{
switch (input.readByte())
{
case varMarker_Int: return var (input.readInt());
case varMarker_Int64: return var (input.readInt64());
case varMarker_BoolTrue: return var (true);
case varMarker_BoolFalse: return var (false);
case varMarker_Double: return var (input.readDouble());
case varMarker_String:
{
MemoryOutputStream mo;
mo.writeFromInputStream (input, numBytes - 1);
return var (mo.toUTF8());
}
case varMarker_Binary:
{
MemoryBlock mb (numBytes - 1);
if (numBytes > 1)
{
const int numRead = input.read (mb.getData(), numBytes - 1);
mb.setSize (numRead);
}
return var (mb);
}
case varMarker_Array:
{
var v;
Array<var>* const destArray = v.convertToArray();
for (int i = input.readCompressedInt(); --i >= 0;)
destArray->add (readFromStream (input));
return v;
}
default:
input.skipNextBytes (numBytes - 1); break;
}
}
return var::null;
}
示例7: getTextBetween
String CodeDocument::getTextBetween (const Position& start, const Position& end) const
{
if (end.getPosition() <= start.getPosition())
return {};
auto startLine = start.getLineNumber();
auto endLine = end.getLineNumber();
if (startLine == endLine)
{
if (auto* line = lines [startLine])
return line->line.substring (start.getIndexInLine(), end.getIndexInLine());
return {};
}
MemoryOutputStream mo;
mo.preallocate ((size_t) (end.getPosition() - start.getPosition() + 4));
auto maxLine = jmin (lines.size() - 1, endLine);
for (int i = jmax (0, startLine); i <= maxLine; ++i)
{
auto& line = *lines.getUnchecked(i);
auto len = line.lineLength;
if (i == startLine)
{
auto index = start.getIndexInLine();
mo << line.line.substring (index, len);
}
else if (i == endLine)
{
len = end.getIndexInLine();
mo << line.line.substring (0, len);
}
else
{
mo << line.line;
}
}
return mo.toUTF8();
}
示例8: readChildElements
//.........这里部分代码省略.........
}
}
else // must be a character block
{
input = preWhitespaceInput; // roll back to include the leading whitespace
MemoryOutputStream textElementContent;
bool contentShouldBeUsed = ! ignoreEmptyTextElements;
for (;;)
{
const juce_wchar c = *input;
if (c == '<')
{
if (input[1] == '!' && input[2] == '-' && input[3] == '-')
{
input += 4;
const int closeComment = input.indexOf (CharPointer_ASCII ("-->"));
if (closeComment < 0)
{
setLastError ("unterminated comment", false);
outOfData = true;
return;
}
input += closeComment + 3;
continue;
}
break;
}
if (c == 0)
{
setLastError ("unmatched tags", false);
outOfData = true;
return;
}
if (c == '&')
{
String entity;
readEntity (entity);
if (entity.startsWithChar ('<') && entity [1] != 0)
{
const String::CharPointerType oldInput (input);
const bool oldOutOfData = outOfData;
input = entity.getCharPointer();
outOfData = false;
while (XmlElement* n = readNextElement (true))
childAppender.append (n);
input = oldInput;
outOfData = oldOutOfData;
}
else
{
textElementContent << entity;
contentShouldBeUsed = contentShouldBeUsed || entity.containsNonWhitespaceChars();
}
}
else
{
for (;; ++input)
{
juce_wchar nextChar = *input;
if (nextChar == '\r')
{
nextChar = '\n';
if (input[1] == '\n')
continue;
}
if (nextChar == '<' || nextChar == '&')
break;
if (nextChar == 0)
{
setLastError ("unmatched tags", false);
outOfData = true;
return;
}
textElementContent.appendUTF8Char (nextChar);
contentShouldBeUsed = contentShouldBeUsed || ! CharacterFunctions::isWhitespace (nextChar);
}
}
}
if (contentShouldBeUsed)
childAppender.append (XmlElement::createTextElement (textElementContent.toUTF8()));
}
}
}
示例9: addEscapeChars
String addEscapeChars (const String& s)
{
MemoryOutputStream out;
writeEscapeChars (out, s.toUTF8().getAddress(), -1, -1, false, true, true);
return out.toUTF8();
}
示例10: toString
String Path::toString() const
{
MemoryOutputStream s (2048);
if (! useNonZeroWinding)
s << 'a';
size_t i = 0;
float lastMarker = 0.0f;
while (i < numElements)
{
const float marker = data.elements [i++];
char markerChar = 0;
int numCoords = 0;
if (marker == moveMarker)
{
markerChar = 'm';
numCoords = 2;
}
else if (marker == lineMarker)
{
markerChar = 'l';
numCoords = 2;
}
else if (marker == quadMarker)
{
markerChar = 'q';
numCoords = 4;
}
else if (marker == cubicMarker)
{
markerChar = 'c';
numCoords = 6;
}
else
{
jassert (marker == closeSubPathMarker);
markerChar = 'z';
}
if (marker != lastMarker)
{
if (s.getDataSize() != 0)
s << ' ';
s << markerChar;
lastMarker = marker;
}
while (--numCoords >= 0 && i < numElements)
{
String coord (data.elements [i++], 3);
while (coord.endsWithChar ('0') && coord != "0")
coord = coord.dropLastCharacters (1);
if (coord.endsWithChar ('.'))
coord = coord.dropLastCharacters (1);
if (s.getDataSize() != 0)
s << ' ';
s << coord;
}
}
return s.toUTF8();
}