本文整理汇总了C++中wxOutputStream::PutC方法的典型用法代码示例。如果您正苦于以下问题:C++ wxOutputStream::PutC方法的具体用法?C++ wxOutputStream::PutC怎么用?C++ wxOutputStream::PutC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxOutputStream
的用法示例。
在下文中一共展示了wxOutputStream::PutC方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteIndent
//! Write the comment strings, if any.
int
wxJSONWriter::WriteComment( wxOutputStream& os, const wxJSONValue& value, bool indent )
{
// the function returns the last character written which should be
// a LF char or -1 in case of errors
// if nothing is written, returns ZERO
int lastChar = 0;
// only write comments if the style include the WRITE_COMMENTS flag
if ( (m_style & wxJSONWRITER_WRITE_COMMENTS ) == 0 ) {
return lastChar;
}
const wxArrayString cmt = value.GetCommentArray();
int cmtSize = cmt.GetCount();
for ( int i = 0; i < cmtSize; i++ ) {
if ( indent ) {
WriteIndent( os );
}
else {
os.PutC( '\t' );
}
WriteString( os, cmt[i]);
lastChar = cmt[i].Last();
if ( lastChar != '\n' ) {
os.PutC( '\n' );
lastChar = '\n';
}
}
return lastChar;
}
示例2:
/*!
The function is called when a value has been written to the JSON
text output and it writes the separator character: LF.
The LF char is actually written only if the wxJSONWRITER_STYLED flag
is specified and wxJSONWRITER_NO_LINEFEEDS is not set.
Returns the last character written which is LF itself or -1 in case
of errors. Note that LF is returned even if the character is not
actually written.
*/
int
wxJSONWriter::WriteSeparator( wxOutputStream& os )
{
int lastChar = '\n';
if ( (m_style & wxJSONWRITER_STYLED) && !(m_style & wxJSONWRITER_NO_LINEFEEDS )) {
os.PutC( '\n' );
}
return lastChar;
}
示例3: integers
/*!
This function is called for every value objects of UINT type.
This function uses the \n snprintf function to get the US-ASCII
representation of the integer and simply copy it to the output stream.
The function prepends a \b plus \b sign if the \c wxJSONWRITER_RECOGNIZE_UNSIGNED
flag is set in the \c m_flags data member.
Returns -1 on stream errors or ZERO if no errors.
*/
int
wxJSONWriter::WriteUIntValue( wxOutputStream& os, const wxJSONValue& value )
{
int r = 0; size_t len;
// prepend a plus sign if the style specifies that unsigned integers
// have to be recognized by the JSON reader
if ( m_style & wxJSONWRITER_RECOGNIZE_UNSIGNED ) {
os.PutC( '+' );
}
char buffer[32]; // need to store 64-bits integers (max 20 digits)
wxJSONRefData* data = value.GetRefData();
wxASSERT( data );
#if defined( wxJSON_64BIT_INT )
#if wxCHECK_VERSION(2, 9, 0 ) || !defined( wxJSON_USE_UNICODE )
// this is fine for wxW 2.9 and for wxW 2.8 ANSI
snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
data->m_value.m_valUInt64 );
#elif wxCHECK_VERSION(3, 0, 0) || !defined( wxJSON_USE_UNICODE )
snprintf( buffer, 32, "%" wxLongLongFmtSpec "u",
data->m_value.m_valUInt64 );
#else
// this is for wxW 2.8 Unicode: in order to use the cross-platform
// format specifier, we use the wxString's sprintf() function and then
// convert to UTF-8 before writing to the stream
wxString s;
s.Printf( _T("%") wxLongLongFmtSpec _T("u"),
data->m_value.m_valInt64 );
wxCharBuffer cb = s.ToUTF8();
const char* cbData = cb.data();
len = strlen( cbData );
wxASSERT( len < 32 );
memcpy( buffer, cbData, len );
buffer[len] = 0;
#endif
#else
snprintf( buffer, 32, "%lu", data->m_value.m_valULong );
#endif
len = strlen( buffer );
os.Write( buffer, len );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
r = -1;
}
return r;
}
示例4: ansiCB
/*!
The function writes the string \c str to the output object that
was specified in the wxJSONWriter::Write() function.
The function may split strings in two or more lines if the
string contains LF characters if the \c m_style data member contains
the wxJSONWRITER_SPLIT_STRING flag.
The function does not actually write the string: for every character
in the provided string the function calls WriteChar() which does
the actual character output.
The function returns ZERO on success or -1 in case of errors.
*/
int
wxJSONWriter::WriteStringValue( wxOutputStream& os, const wxString& str )
{
// JSON values of type STRING are written by converting the whole string
// to UTF-8 and then copying the UTF-8 buffer to the 'os' stream
// one byte at a time and processing them
os.PutC( '\"' ); // open quotes
// the buffer that has to be written is either UTF-8 or ANSI c_str() depending
// on the 'm_noUtf8' flag
char* writeBuff = 0;
wxCharBuffer utf8CB = str.ToUTF8(); // the UTF-8 buffer
#if !defined( wxJSON_USE_UNICODE )
wxCharBuffer ansiCB( str.c_str()); // the ANSI buffer
if ( m_noUtf8 ) {
writeBuff = ansiCB.data();
}
else {
writeBuff = utf8CB.data();
}
#else
writeBuff = utf8CB.data();
#endif
// NOTE: in ANSI builds UTF-8 conversion may fail (see samples/test5.cpp,
// test 7.3) although I do not know why
if ( writeBuff == 0 ) {
const char* err = "<wxJSONWriter::WriteStringValue(): error converting the string to a UTF8 buffer>";
os.Write( err, strlen( err ));
return 0;
}
size_t len = strlen( writeBuff );
int lastChar = 0;
// store the column at which the string starts
// splitting strings only happen if the string starts within
// column wxJSONWRITER_LAST_COL (default 50)
// see 'include/wx/json_defs.h' for the defines
int tempCol = m_colNo;
// now write the UTF8 buffer processing the bytes
size_t i;
for ( i = 0; i < len; i++ ) {
bool shouldEscape = false;
unsigned char ch = *writeBuff;
++writeBuff; // point to the next byte
// the escaped character
char escCh = 0;
// for every character we have to check if it is a character that
// needs to be escaped: note that characters that should be escaped
// may be not if some writer's flags are specified
switch ( ch ) {
case '\"' : // quotes
shouldEscape = true;
escCh = '\"';
break;
case '\\' : // reverse solidus
shouldEscape = true;
escCh = '\\';
break;
case '/' : // solidus
shouldEscape = true;
escCh = '/';
break;
case '\b' : // backspace
shouldEscape = true;
escCh = 'b';
break;
case '\f' : // formfeed
shouldEscape = true;
escCh = 'f';
break;
case '\n' : // newline
shouldEscape = true;
escCh = 'n';
break;
case '\r' : // carriage-return
shouldEscape = true;
escCh = 'r';
break;
case '\t' : // horizontal tab
shouldEscape = true;
escCh = 't';
break;
default :
//.........这里部分代码省略.........
示例5: if
//.........这里部分代码省略.........
case wxJSONTYPE_INT64 :
lastChar = WriteIntValue( os, value );
break;
case wxJSONTYPE_UINT :
case wxJSONTYPE_USHORT :
case wxJSONTYPE_ULONG :
case wxJSONTYPE_UINT64 :
lastChar = WriteUIntValue( os, value );
break;
case wxJSONTYPE_NULL :
lastChar = WriteNullValue( os );
break;
case wxJSONTYPE_BOOL :
lastChar = WriteBoolValue( os, value );
break;
case wxJSONTYPE_DOUBLE :
lastChar = WriteDoubleValue( os, value );
break;
case wxJSONTYPE_STRING :
case wxJSONTYPE_CSTRING :
lastChar = WriteStringValue( os, value.AsString());
break;
case wxJSONTYPE_MEMORYBUFF :
lastChar = WriteMemoryBuff( os, value.AsMemoryBuff());
break;
case wxJSONTYPE_ARRAY :
++m_level;
os.PutC( '[' );
// the inline comment for objects and arrays are printed in the open char
if ( commentPos == wxJSONVALUE_COMMENT_INLINE ) {
commentPos = -1; // we have already written the comment
lastChar = WriteComment( os, value, false );
if ( lastChar < 0 ) {
return lastChar;
}
if ( lastChar != '\n' ) {
lastChar = WriteSeparator( os );
}
}
else { // comment is not to be printed inline, so write a LF
lastChar = WriteSeparator( os );
if ( lastChar < 0 ) {
return lastChar;
}
}
// now iterate through all sub-items and call DoWrite() recursively
size = value.Size();
for ( int i = 0; i < size; i++ ) {
bool comma = false;
if ( i < size - 1 ) {
comma = true;
}
wxJSONValue v = value.ItemAt( i );
lastChar = DoWrite( os, v, 0, comma );
if ( lastChar < 0 ) {
return lastChar;
}
}
示例6: wxASSERT
/*!
The type wxJSONTYPE_MEMORYBUFF is a \b wxJSON extension that is not correctly read by
other JSON implementations.
By default, the function writes such a type as an array of INTs as follows:
\code
[ 0,32,45,255,6,...]
\endcode
If the writer object was constructed using the \c wxJSONWRITER_MEMORYBUFF flag, then
the output is much more compact and recognized by the \b wxJSON reader as a memory buffer
type:
\code
'00203FFF06..'
\endcode
*/
int
wxJSONWriter::WriteMemoryBuff( wxOutputStream& os, const wxMemoryBuffer& buff )
{
#define MAX_BYTES_PER_ROW 20
char str[16];
// if STYLED and SPLIT_STRING flags are set, the function writes 20 bytes on every row
// the following is the counter of bytes written.
// the string is splitted only for the special meory buffer type, not for array of INTs
int bytesWritten = 0;
bool splitString = false;
if ( (m_style & wxJSONWRITER_STYLED) &&
(m_style & wxJSONWRITER_SPLIT_STRING)) {
splitString = true;
}
size_t buffLen = buff.GetDataLen();
unsigned char* ptr = (unsigned char*) buff.GetData();
wxASSERT( ptr );
char openChar = '\'';
char closeChar = '\'';
bool asArray = false;
if ( (m_style & wxJSONWRITER_MEMORYBUFF ) == 0 ) {
// if the special flag is not specified, write as an array of INTs
openChar = '[';
closeChar = ']';
asArray = true;
}
// write the open character
os.PutC( openChar );
for ( size_t i = 0; i < buffLen; i++ ) {
unsigned char c = *ptr;
++ptr;
if ( asArray ) {
snprintf( str, 14, "%d", c );
size_t len = strlen( str );
wxASSERT( len <= 3 );
wxASSERT( len >= 1 );
str[len] = ',';
// do not write the comma char for the last element
if ( i < buffLen - 1 ) {
++len;
}
os.Write( str, len );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
return -1;
}
}
else {
// now convert the byte in two hex digits
char c1 = c / 16;
char c2 = c % 16;
c1 += '0';
c2 += '0';
if ( c1 > '9' ) {
c1 += 7;
}
if ( c2 > '9' ) {
c2 += 7;
}
os.PutC( c1 );
os.PutC( c2 );
if ( os.GetLastError() != wxSTREAM_NO_ERROR ) {
return -1;
}
if ( splitString ) {
++bytesWritten;
}
if (( bytesWritten >= MAX_BYTES_PER_ROW ) && ((buffLen - i ) >= 5 )) {
// split the string if we wrote 20 bytes, but only is we have to
// write at least 5 bytes
os.Write( "\'\n", 2 );
int lastChar = WriteIndent( os, m_level + 2 ); // write indentation
os.PutC( '\'' ); // reopen quotes
if ( lastChar < 0 ) {
return lastChar;
}
bytesWritten = 0;
}
}
}
//.........这里部分代码省略.........