wstring ncbi_Utf8ToWstring(
const char*utf8)
60IOS_BASE::fmtflags
f= is.flags();
61is.unsetf(IOS_BASE::skipws);
69CNcbiIstream::sentry s(is);
91 if(delim_pos !=
NPOS) {
96ch = is.rdbuf()->sgetc();
106 if(
size== max_size) {
113 if(pos ==
sizeof(
buf)) {
140 #if defined(NCBI_USE_OLD_IOSTREAM) 162 if(
size== max_size) {
167is.get(
buf,
n<
sizeof(
buf) ?
n:
sizeof(
buf), delim);
168 n= (size_t) is.gcount();
172}
while( is.good() );
186 #if defined(NCBI_OS_MSWIN) 187 static const chars_Endl[] =
"\r\n";
189 static const chars_Endl[] =
"\n";
198 #if defined(NCBI_OS_MSWIN) 200 if(!
str.empty() &&
str[
str.length() - 1] ==
'\r')
201 str.resize(
str.length() - 1);
202 #elif defined(NCBI_OS_DARWIN) 213 if(!os.good() || is.bad())
221 returnos.good() && os.flush() ?
true:
false;
227 boolsuccess =
false;
247 "Output stream already in bad state");
254 "Input stream already in bad state (at EOF)");
260 while(ninstream > 0 || ninbuffer > 0) {
262 autonwanted =
min(
sizeof(
buffer) - ninbuffer, ninstream);
263streamsize nread = 0;
265is.read(
buffer+ ninbuffer, nwanted);
272 autonwritten =
outbuf->sputn(
buffer, nread + ninbuffer);
273 if( os.bad() || nwritten == 0) {
278ninbuffer = nread + ninbuffer - nwritten;
307 size_tbuf_size =
sizeof(
buf);
312 if(
str->size() < str_size + buf_size)
313 str->resize(str_size + buf_size);
319is.read(
str? &(*
str)[str_size] :
buf, buf_size);
322 str->resize(str_size);
325streamsize
count= is.gcount();
326str_size += (size_t)
count;
328 if((
size_t)
count== buf_size) {
329 if(buf_size < (1UL << 20))
331 str->resize(str_size + buf_size);
339 str->resize(str_size);
341 if(!(str_size -= pos)) {
348IOS_BASE::iostate iostate = is.rdstate();
359 charc1 = (char)is1.get();
360 charc2 = (char)is2.get();
365 returnis1.eof() && is2.eof();
371 char*
buf,
size_tbuf_size,
char*& pos,
size_t& sizeleft)
376is.read(
buf, buf_size);
377sizeleft = (size_t) is.gcount();
387&& (c ==
'\n'|| c ==
'\r')) ||
389&&
isspace((
unsigned char) c)) );
400 char* buf1 =
new char[buf_size];
401 char* buf2 =
new char[buf_size];
402 size_tsize1 = 0, size2 = 0;
403 char*pos1 = 0, *pos2 = 0;
406 charc1 =
x_GetChar(is1,
mode, buf1, buf_size, pos1, size1);
407 charc2 =
x_GetChar(is2,
mode, buf2, buf_size, pos2, size2);
415 returnequal && is1.eof() && is2.eof();
427CNcbiOstrstreamToString::operator
string(
void)
const 429 #ifdef NCBI_SHUN_OSTRSTREAM 436 const char*
str= m_Out.str();
437m_Out.freeze(
false);
445 #ifdef NCBI_SHUN_OSTRSTREAM 451s.
m_Out.freeze(
false);
462 out.put(
char(
toupper((
unsigned char)(*c))));
471 out.put(
char(
tolower((
unsigned char)(*c))));
479 for(
const char* c = s.
m_String; *c; ++c ) {
480 out.put(
char(
toupper((
unsigned char)(*c))));
488 for(
const char* c = s.
m_String; *c; ++c ) {
489 out.put(
char(
tolower((
unsigned char)(*c))));
495 #ifdef NCBI_COMPILER_MSVC 496 # if _MSC_VER >= 1200 && _MSC_VER < 1300 507 static const charkHex[] =
"0123456789ABCDEF";
511 case '\0': s =
"\\0";
break;
512 case '\a': s =
"\\a";
break;
513 case '\b': s =
"\\b";
break;
514 case '\f': s =
"\\f";
break;
515 case '\n': s =
"\\n";
break;
516 case '\r': s =
"\\r";
break;
517 case '\t': s =
"\\t";
break;
518 case '\v': s =
"\\v";
break;
519 case '\\': s =
"\\\\";
break;
520 case '\'': s =
"\\'";
break;
521 case '"': s =
"\\\"";
break;
523 if( !
isprint((
unsigned char) c) ) {
525s += kHex[(
unsignedchar) c / 16];
526s += kHex[(
unsignedchar) c % 16];
539 case '\a':
out.write(
"\\a", 2);
return;
540 case '\b':
out.write(
"\\b", 2);
return;
541 case '\f':
out.write(
"\\f", 2);
return;
542 case '\n':
out.write(
"\\n", 2);
return;
543 case '\r':
out.write(
"\\r", 2);
return;
544 case '\t':
out.write(
"\\t", 2);
return;
545 case '\v':
out.write(
"\\v", 2);
return;
546 case '\\':
out.write(
"\\\\", 2);
return;
547 case '\'':
out.write(
"\\'", 2);
return;
548 case '"':
out.write(
"\\\"", 2);
return;
550 if(p ==
'?'||
n==
'?')
551 out.write(
"\\?", 2);
556 if(
isprint((
unsigned char) c) ) {
563 boolfull =
'0'<=
n&&
n<=
'7'?
true:
false;
569v = (
unsignedchar) c >> 6;
571octal[k++] = char(
'0'+ v);
574v = ((
unsignedchar) c >> 3) & 7;
576octal[k++] = char(
'0'+ v);
578v = (
unsignedchar) c & 7;
579octal[k++] = char(
'0'+ v);
580 out.write(octal, k);
590 for(
size_t i= 0;
i<
size- 1; ++
i) {
615 #if defined(NCBI_COMPILER_WORKSHOP) 617 # if (NCBI_COMPILER_VERSION == 530) 621istream& istream::read(
char*s, streamsize
n)
623sentry ipfx(*
this, 1);
626 if(rdbuf()->sgetc() == traits_type::eof()) {
632__chcount = rdbuf()->sgetn(s,
n);
633 if(__chcount == 0) {
635}
else if(__chcount <
n) {
636setstate(eofbit | failbit);
641setstate(badbit | failbit);
659 if(!
input.good()) {
663 const intbuf_size = 4096;
664 char tmp[buf_size+2];
668 const intbom_max = 4;
669memset(
tmp,0,bom_max);
675 if(
n>= 3 && uc[0] == 0xEF && uc[1] == 0xBB && uc[2] == 0xBF) {
680 else if(
n>= 2 && (us[0] == 0xFEFF || us[0] == 0xFFFE)) {
681 if(us[0] == 0xFEFF) {
697 while(
n!= 0 || (
input.good() && !
input.eof())) {
718 for(
n=
n/2;
n--; ++u) {
757 "ReadIntoUtf8: cannot guess text encoding");
786 if(
input.good()) {
787 const intbom_max = 4;
789memset(
tmp, 0, bom_max);
794 if(
n== 1 && (uc[0] == 0xEF || uc[0] == 0xFE || uc[0] == 0xFF)){
796 if(
input.gcount() == 1) {
798 if(us[0] == 0xFEFF) {
800}
else if(us[0] == 0xFFFE) {
802}
else if(uc[1] == 0xBB) {
804 if(
input.gcount() == 1) {
816}
else if(
n== 1) {
841 #ifdef WORDS_BIGENDIAN 848 #ifdef WORDS_BIGENDIAN 867 #if defined(NCBI_USE_OLD_IOSTREAM) 872 return str.empty() ? os : os <<
str.c_str();
887end = (streamsize) end < is.width() ? end : is.width();
890 for(ch = is.rdbuf()->sbumpc();
891ch != EOF && !
isspace((
unsigned char) ch);
892ch = is.rdbuf()->sbumpc()) {
893 str.append(1, (
char) ch);
Byte Order Mark helper class to use in serialization.
Utility class for automatic conversion of strings to all lowercase letters.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Utility class for automatic conversion of strings (that may contain non-graphical characters) to a sa...
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Utility class for automatic conversion of strings to all uppercase letters.
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
static const char * str(char *buf, int n)
CNcbiIstream & operator>>(CNcbiIstream &s, const getcontig &c)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define NCBI_CATCH_ALL(message)
This macro is deprecated - use *_X or *_XX variant instead of it.
uint8_t Uint1
1-byte (8-bit) unsigned integer
unsigned char Uchar
Alias for unsigned char.
uint16_t Uint2
2-byte (16-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
void NcbiStreamCopyThrow(CNcbiOstream &os, CNcbiIstream &is)
Same as NcbiStreamCopy() but throws an CCoreException when copy fails.
EEncodingForm
Helper functions to read plain-text data streams.
CNcbiOstream & operator<<(CNcbiOstream &out, const CNcbiOstrstreamToString &s)
string Printable(char c)
Convert one single character to a "printable" form.
EEncodingForm GetTextEncodingForm(CNcbiIstream &input, EBOMDiscard discard_bom)
Detect if the stream has BOM.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
EBOMDiscard
Whether to discard BOM or to keep it in the input stream.
static void Pushback(CNcbiIstream &is, CT_CHAR_TYPE *buf, streamsize buf_size, void *del_ptr)
bool NcbiStreamCompare(CNcbiIstream &is1, CNcbiIstream &is2)
Compare stream contents in binary form.
const char * Endl(void)
Platform-specific EndOfLine.
ECompareTextMode
Mode to compare streams in text form.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
EEncodingForm ReadIntoUtf8(CNcbiIstream &input, CStringUTF8 *result, EEncodingForm ef, EReadUnknownNoBOM what_if_no_bom)
Read all input data from stream and try convert it into UTF8 string.
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
EReadUnknownNoBOM
How to read the text if the encoding form is not known (i.e.
bool NcbiStreamCompareText(CNcbiIstream &is1, CNcbiIstream &is2, ECompareTextMode mode, size_t buf_size)
Compare stream contents in text form.
size_t NcbiStreamToString(string *str, CNcbiIstream &is, size_t pos)
Input the entire contents of an istream into a string (NULL causes drain).
EEncodingForm GetEncodingForm(void) const
@ eEncodingForm_Utf16Foreign
Stream has UTF16 BOM. Byte order is nonnative for this OS.
@ eEncodingForm_Utf8
Stream has UTF8 BOM.
@ eEncodingForm_ISO8859_1
Stream has no BOM.
@ eEncodingForm_Windows_1252
Stream has no BOM.
@ eEncodingForm_Unknown
Stream has no BOM.
@ eEncodingForm_Utf16Native
Stream has UTF16 BOM. Byte order is native for this OS.
@ eBOM_Keep
Push the read BOM bytes back into the input stream.
@ eCompareText_IgnoreEol
Skip end-of-line characters ('\r' and ' ')
@ eCompareText_IgnoreWhiteSpace
@ eNoBOM_GuessEncoding
Try to guess the text's encoding form.
NCBI_NS_STD::string::size_type SIZE_TYPE
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static EEncoding GuessEncoding(const CTempString &src)
Guess the encoding of the C/C++ string.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
static SIZE_TYPE GetValidBytesCount(const CTempString &src)
Get the number of valid UTF-8 bytes (code units) in buffer.
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
unsigned int
A callback function used to compare two keys in a database.
const struct ncbi::grid::netcache::search::fields::SIZE size
void NcbiStreamCopyHead(CNcbiOstream &os, CNcbiIstream &is, SIZE_TYPE count)
CNcbiIstream & NcbiGetline(CNcbiIstream &is, string &str, const string &delims, SIZE_TYPE *count)
static void s_WritePrintable(CNcbiOstream &out, char p, char c, char n)
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, SIZE_TYPE *count)
static char x_GetChar(CNcbiIstream &is, ECompareTextMode mode, char *buf, size_t buf_size, char *&pos, size_t &sizeleft)
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
uchar outbuf[(1000000+1000000)]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4