NCBI C++ ToolKit
objistrxml.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: objistrxml.cpp 97585 2022-08-01 18:52:25Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * !!! PUT YOUR DESCRIPTION HERE !!!
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/tempstr.hpp>
36 #include <serial/objistrxml.hpp>
37 #include <serial/enumvalues.hpp>
38 #include <serial/objhook.hpp>
40 #include <serial/impl/choice.hpp>
41 #include <serial/impl/ptrinfo.hpp>
42 #include <serial/impl/continfo.hpp>
45 #include <serial/impl/memberid.hpp>
46 
48 
49 static
50 const char* s_SchemaInstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
51 
53 {
54  return new CObjectIStreamXml();
55 }
56 
59  m_TagState(eTagOutside), m_LeadingWs(0), m_Attlist(false),
60  m_StdXml(false), m_Doctype_found(false), m_IsNil(false),
61  m_Encoding( eEncoding_Unknown ),
62  m_StringEncoding( eEncoding_UTF8 ),
63  m_SkipNextTag(false)
64 {
65  m_Utf8Pos = m_Utf8Buf.begin();
66 }
67 
70  m_TagState(eTagOutside), m_LeadingWs(0), m_Attlist(false),
71  m_StdXml(false), m_Doctype_found(false), m_IsNil(false),
72  m_Encoding( eEncoding_Unknown ),
73  m_StringEncoding( eEncoding_UTF8 ),
74  m_SkipNextTag(false)
75 {
76  m_Utf8Pos = m_Utf8Buf.begin();
77  Open(in, deleteIn);
78 }
79 
81 {
82 }
83 
85 {
87  if (GetStackDepth() > 1) {
88  return;
89  }
91  m_LeadingWs = 0;
92  m_LastTag.clear();
93  m_RejectedTag.clear();
94  m_Attlist = false;
95  m_IsNil = false;;
96  m_LastPrimitive.clear();
97  m_CurrNsPrefix.clear();
98  m_Utf8Buf.clear();
99  m_Utf8Pos = m_Utf8Buf.begin();
100  m_SkipNextTag = false;
101 }
102 
104 {
105  return m_Encoding;
106 }
107 
109 {
110  m_StringEncoding = enc;
111 }
112 
114 {
115  return m_StringEncoding;
116 }
117 
119 {
121  return true;
122  }
123  try {
125  } catch (...) {
126  return true;
127  }
128  return false;
129 }
130 
131 void CObjectIStreamXml::Location(string& loc_type, size_t& loc) const
132 {
133  loc_type = "line";
134  loc = m_Input.GetLine();
135 }
136 
138 {
139  if ( set ) {
141  }
142  else {
144  }
145  if (set) {
146  m_StdXml = false;
147  }
148 }
149 
150 template<typename Type> inline
152 {
154 }
155 
156 static inline
157 bool IsBaseChar(char c)
158 {
159  return
160  (c >= 'A' && c <='Z') ||
161  (c >= 'a' && c <= 'z') ||
162  (c >= '\xC0' && c <= '\xD6') ||
163  (c >= '\xD8' && c <= '\xF6') ||
164  (c >= '\xF8' && c <= '\xFF');
165 }
166 
167 static inline
168 bool IsDigit(char c)
169 {
170  return c >= '0' && c <= '9';
171 }
172 
173 static inline
174 bool IsIdeographic(char /*c*/)
175 {
176  return false;
177 }
178 
179 static inline
180 bool IsLetter(char c)
181 {
182  return IsBaseChar(c) || IsIdeographic(c);
183 }
184 
185 static inline
186 bool IsFirstNameChar(char c)
187 {
188  return IsLetter(c) || c == '_' || c == ':';
189 }
190 
191 static inline
192 bool IsCombiningChar(char /*c*/)
193 {
194  return false;
195 }
196 
197 static inline
198 bool IsExtender(char c)
199 {
200  return c == '\xB7';
201 }
202 
203 static inline
204 bool IsNameChar(char c)
205 {
206  return IsFirstNameChar(c) ||
207  IsDigit(c) || c == '.' || c == '-' ||
208  IsCombiningChar(c) || IsExtender(c);
209 }
210 
211 static inline
212 bool IsWhiteSpace(char c)
213 {
214  return c == ' ' || c == '\t' || c == '\n' || c == '\r';
215 }
216 
217 static inline
218 bool IsEndOfTagChar(char c)
219 {
220  return c == '>' || c == '/';
221 }
222 
224 {
225 // _ASSERT(InsideTag());
226  for ( ;; ) {
227  char c = m_Input.SkipSpaces();
228  switch ( c ) {
229  case '\t':
230  m_Input.SkipChar();
231  continue;
232  case '\r':
233  case '\n':
234  m_Input.SkipChar();
236  continue;
237  default:
238  return c;
239  }
240  }
241 }
242 
244 {
245  _ASSERT(OutsideTag());
246  for ( ;; ) {
247  Int8 before = m_Input.GetStreamPosAsInt8();
248  char c = m_Input.SkipSpaces();
249  m_LeadingWs += m_Input.GetStreamPosAsInt8() - before;
250  switch ( c ) {
251  case '\t':
252  m_Input.SkipChar();
253  continue;
254  case '\r':
255  case '\n':
256  m_Input.SkipChar();
258  continue;
259  case '<':
260 // https://www.w3.org/TR/xml11/#sec-pi
261  if ( m_Input.PeekChar(1) == '?') {
262  m_Input.SkipChar();
263  Found_lt();
264  SkipQDecl();
265  return SkipWSAndComments();
266  }
267 // https://www.w3.org/TR/xml11/#sec-comments
268  if ( m_Input.PeekChar(1) == '!' &&
269  m_Input.PeekChar(2) == '-' &&
270  m_Input.PeekChar(3) == '-' ) {
271  // start of comment
272  m_Input.SkipChars(4);
273  if (m_Input.PeekChar(0) == '-' &&
274  m_Input.PeekChar(1) == '-') {
276  "double-hyphen '--' is not allowed in XML comments");
277  }
278  for ( ;; ) {
279  m_Input.FindChar('-');
280  if ( m_Input.PeekChar(1) == '-' ) {
281  // --
282  if ( m_Input.PeekChar(2) == '>' ) {
283  // -->
284  m_Input.SkipChars(3);
285  break;
286  }
287  else {
288  // --[^>]
290  "double-hyphen '--' is not allowed in XML comments");
291  }
292  }
293  else {
294  // -[^-]
295  m_Input.SkipChars(2);
296  }
297 
298  }
299  continue; // skip the next WS or comment
300  }
301  return '<';
302  default:
303  return c;
304  }
305  }
306 }
307 
309 {
310  char c = SkipWS();
311  if (m_Attlist) {
312  if (c == '=') {
313  m_Input.SkipChar();
314  c = SkipWS();
315  if (c == '\"') {
316  m_Input.SkipChar();
317  return;
318  }
319  }
320  if (c == '\"') {
321  m_Input.SkipChar();
323  return;
324  }
325  if (c == '/' && m_Input.PeekChar(1) == '>' ) {
326  m_Input.SkipChars(2);
328  Found_slash_gt();
329  return;
330  }
331  }
332  if ( c != '>' ) {
334  if ( c != '>' ) {
335  ThrowError(fFormatError, "'>' expected");
336  }
337  }
338  m_Input.SkipChar();
339  Found_gt();
340 }
341 
343 {
344  if (!StackIsEmpty() && TopFrame().GetNotag()) {
345  if (SelfClosedTag()) {
346  return true;
347  }
348  }
349  if( InsideOpeningTag() ) {
350  char c = SkipWS();
351  if (m_Attlist) {
352  return false;
353  }
354  if ( c == '/' && m_Input.PeekChar(1) == '>' ) {
355  // end of self closed tag
356  m_Input.SkipChars(2);
357  Found_slash_gt();
358  return true;
359  }
360 
361  if ( c != '>' ) {
363  if ( c == '/' && m_Input.PeekChar(1) == '>' ) {
364  // end of self closed tag
365  m_Input.SkipChars(2);
366  Found_slash_gt();
367  return true;
368  }
369  if ( c != '>' )
370  ThrowError(fFormatError, "end of tag expected");
371  }
372 
373  // end of open tag
374  m_Input.SkipChar(); // '>'
375  Found_gt();
376  }
377  return SelfClosedTag();
378 }
379 
381 {
382  if (ExpectSpecialCase()==0) {
383  return false;
384  }
385  bool empty = !m_Attlist &&
386  ( SelfClosedTag() ||
388  (m_Input.PeekChar(0) == '<' && m_Input.PeekChar(1) == '/')
389  );
390  if (empty) {
392  m_IsNil=false;
394 // NCBI_THROW(CSerialException,eNullValue, kEmptyStr);
395  return true;
396  }
397  if ( GetMemberDefault()) {
399  return true;
400  }
401  }
402  return false;
403 }
404 
406 {
407  BeginData();
408  // find beginning '<'
409  char c = SkipWSAndComments();
410  if ( c != '<' )
411  ThrowError(fFormatError, "'<' expected");
412  c = m_Input.PeekChar(1);
413  if ( c == '/' )
414  ThrowError(fFormatError, "unexpected '</'");
415  m_Input.SkipChar();
416  Found_lt();
417  return c;
418 }
419 
421 {
422  BeginData();
423  // find beginning '<'
424  char c = SkipWSAndComments();
425  if ( c != '<' || m_Input.PeekChar(1) != '/' )
426  ThrowError(fFormatError, "'</' expected");
427  m_Input.SkipChars(2);
428  Found_lt_slash();
429  return m_Input.PeekChar();
430 }
431 
433 {
434  _ASSERT(InsideTag());
435  if ( !IsFirstNameChar(c) )
437  "Name begins with an invalid character: #"
438  +NStr::UIntToString((unsigned int)c));
439 
440  // find end of tag name
441  size_t i = 1, iColon = 0;
442  while ( IsNameChar(c = m_Input.PeekChar(i)) ) {
443  if (!m_Doctype_found && c == ':') {
444  iColon = i+1;
445  }
446  ++i;
447  }
448 
449  // save beginning of tag name
450  const char* ptr = m_Input.GetCurrentPos();
451  m_LastTag = string(ptr+iColon, i-iColon);
452  string ns_prefix;
453  if (iColon > 1) {
454  ns_prefix = string(ptr, iColon-1);
455  }
457 
458  // check end of tag name
459  if (c == '\n' || c == '\r') {
460  m_Input.SkipChar();
462  }
463  if (iColon > 1) {
464  if (ns_prefix == "xmlns") {
465  string value;
466  ReadAttributeValue(value, true);
467  if (m_LastTag == m_CurrNsPrefix) {
468  size_t depth = GetStackDepth();
469  TTypeInfo type=0;
470  if (depth > 1 && FetchFrameFromTop(1).HasTypeInfo()) {
472  if (type->GetName().empty() &&
473  depth > 3 && FetchFrameFromTop(3).HasTypeInfo()) {
475  }
476  }
477  if (type && type->HasNamespaceName()) {
478  type->SetNamespacePrefix(m_CurrNsPrefix);
479  }
480  }
483  char ch = SkipWS();
484  return IsEndOfTagChar(ch) ? CTempString() : ReadName(ch);
485  } else if (ns_prefix == "xml") {
486  iColon = 0;
487  } else {
488  m_CurrNsPrefix = ns_prefix;
489  }
490  } else {
491  if (!m_Attlist) {
492  m_CurrNsPrefix.erase();
493  }
494  if (m_Attlist && m_LastTag == "xmlns") {
495  string value;
496  ReadAttributeValue(value, true);
497  if (GetStackDepth() > 1 && FetchFrameFromTop(1).HasTypeInfo()) {
499  if (type->HasNamespaceName()) {
500  type->SetNamespacePrefix(m_CurrNsPrefix);
501  }
502  }
505  char ch = SkipWS();
506  return IsEndOfTagChar(ch) ? CTempString() : ReadName(ch);
507  }
508  }
509 #if defined(NCBI_SERIAL_IO_TRACE)
510  cout << ", Read= " << m_LastTag;
511 #endif
512  if (m_Attlist && m_LastTag.size() == 3 &&
513  m_LastTag == "nil" &&
516  string value;
517  ReadAttributeValue(value, true);
519  char ch = SkipWS();
520  return IsEndOfTagChar(ch) ? CTempString() : ReadName(ch);
521  }
522  return m_LastTag;
523 }
524 
526 {
527  _ASSERT(!m_RejectedTag.empty());
529  m_RejectedTag.erase();
531 #if defined(NCBI_SERIAL_IO_TRACE)
532  cout << ", Redo= " << m_LastTag;
533 #endif
534  return m_LastTag;
535 }
536 
538 {
540  m_Input.SkipChar();
541  m_Input.FindChar(c);
542  m_Input.SkipChar();
543 }
544 
546 {
548  m_Input.SkipChar();
549 
550  CTempString tagName;
551  tagName = ReadName( SkipWS());
552 // _ASSERT(tagName == "xml");
553  for (;;) {
554  char ch = SkipWS();
555  if (ch == '?') {
556  break;
557  }
558  tagName = ReadName(ch);
559  string value;
561  if (tagName == "encoding") {
562  if (NStr::CompareNocase(value.c_str(),"UTF-8") == 0) {
564  } else if (NStr::CompareNocase(value.c_str(),"ISO-8859-1") == 0) {
566  } else if (NStr::CompareNocase(value.c_str(),"Windows-1252") == 0) {
568  } else {
569  ThrowError(fFormatError, "unsupported encoding: " + value);
570  }
571  break;
572  }
573  }
574  for ( ;; ) {
575  m_Input.FindChar('?');
576  if ( m_Input.PeekChar(1) == '>' ) {
577  // ?>
578  m_Input.SkipChars(2);
579  Found_gt();
580  return;
581  }
582  else
583  m_Input.SkipChar();
584  }
585 }
586 
588 {
589 // check for UTF8 Byte Order Mark (EF BB BF)
590 // http://unicode.org/faq/utf_bom.html#BOM
591  {
592  char c = m_Input.PeekChar();
593  if ((unsigned char)c == 0xEF) {
594  if ((unsigned char)m_Input.PeekChar(1) == 0xBB &&
595  (unsigned char)m_Input.PeekChar(2) == 0xBF) {
596  m_Input.SkipChars(3);
598  }
599  }
600  }
601 
602  m_Doctype_found = false;
603  if (GetStackDepth() > 0) {
604  const CObjectStack::TFrame& top = TopFrame();
605  if (top.HasTypeInfo()) {
607  }
608  }
609  for ( ;; ) {
610  switch ( BeginOpeningTag() ) {
611  case '?':
612  SkipQDecl();
613  break;
614  case '!':
615  {
616  m_Input.SkipChar();
617  CTempString tagName = ReadName(m_Input.PeekChar());
618  if ( tagName == "DOCTYPE" ) {
619 // m_Doctype_found = true;
620  ReadName(SkipWS());
621  // skip the rest of !DOCTYPE
622  for ( ;; ) {
623  char c = SkipWS();
624  if ( c == '>' ) {
625  m_Input.SkipChar();
626  Found_gt();
627  break;
628  }
629  else if ( c == '"' || c == '\'' ) {
631  }
632  else {
633  ReadName(c);
634  }
635  }
636  }
637  else {
638  // unknown tag
640  "unknown tag in file header: "+string(tagName));
641  }
642  }
643  break;
644  default:
645  {
646  string typeName = ReadName(m_Input.PeekChar());
647  if (!m_Doctype_found && !StackIsEmpty()) {
648  // verify typename
649  const CObjectStack::TFrame& top = TopFrame();
651  top.HasTypeInfo()) {
652  const string& tname = top.GetTypeInfo()->GetName();
653  if ( !typeName.empty() && !tname.empty() && typeName != tname ) {
654  string tmp = m_CurrNsPrefix + ":" + typeName;
655  if (tmp == tname) {
656  typeName = tmp;
657  m_LastTag = tmp;
658  m_CurrNsPrefix.erase();
659  m_Doctype_found = true;
660  }
661  }
662  }
663  }
664  UndoClassMember();
665  return typeName;
666  }
667 /*
668  m_Input.UngetChar('<');
669  Back_lt();
670  ThrowError(fFormatError, "unknown DOCTYPE");
671 */
672  }
673  }
674  return NcbiEmptyString;
675 }
676 
678 {
679  if (!m_RejectedTag.empty()) {
680  return m_RejectedTag;
681  }
682  string typeName = ReadName(BeginOpeningTag());
683  UndoClassMember();
684  return typeName;
685 }
686 
687 void CObjectIStreamXml::FindFileHeader(bool find_XMLDecl)
688 {
689  char c;
690  for (;;) {
691  c = m_Input.PeekChar();
692  if (c == '<') {
693  if (!find_XMLDecl) {
694  return;
695  }
696  if (m_Input.PeekChar(1) == '?' &&
697  m_Input.PeekChar(2) == 'x' &&
698  m_Input.PeekChar(3) == 'm' &&
699  m_Input.PeekChar(4) == 'l') {
700  return;
701  }
702  }
703  m_Input.SkipChar();
704  }
705 }
706 
708 {
709  if (x_IsStdXml()) {
710  if (TopFrame().HasTypeInfo()) {
712  if (type->HasNamespaceName()) {
713  string nsName = type->GetNamespaceName();
714  string nsPrefix = m_NsNameToPrefix[nsName];
715 // not sure about it - should we erase them or not?
716 // m_NsNameToPrefix.erase(nsName);
717 // m_NsPrefixToName.erase(nsPrefix);
718  }
719  }
720  if (GetStackDepth() <= 2) {
723  }
724  }
725 }
726 
727 int CObjectIStreamXml::ReadEscapedChar(char endingChar, bool* encoded)
728 {
729  char c = m_Input.PeekChar();
730  if (encoded) {
731  *encoded = false;
732  }
733  if ( c == '&' ) {
734  if (encoded) {
735  *encoded = true;
736  }
737  m_Input.SkipChar();
738  const size_t limit = 32;
739  size_t offset = m_Input.PeekFindChar(';', limit);
740  if ( offset >= limit )
741  ThrowError(fFormatError, "entity reference is too long");
742  const char* p = m_Input.GetCurrentPos(); // save entity string pointer
743  m_Input.SkipChars(offset + 1); // skip it
744  if ( offset == 0 )
745  ThrowError(fFormatError, "invalid entity reference");
746  if ( *p == '#' ) {
747  const char* end = p + offset;
748  ++p;
749  // char ref
750  if ( p == end )
751  ThrowError(fFormatError, "invalid char reference");
752  unsigned v = 0;
753  if ( *p == 'x' ) {
754  // hex
755  if ( ++p == end )
756  ThrowError(fFormatError, "invalid char reference");
757  do {
758  c = *p++;
759  if ( c >= '0' && c <= '9' )
760  v = v * 16 + (c - '0');
761  else if ( c >= 'A' && c <='F' )
762  v = v * 16 + (c - 'A' + 0xA);
763  else if ( c >= 'a' && c <='f' )
764  v = v * 16 + (c - 'a' + 0xA);
765  else
767  "invalid symbol in char reference");
768  } while ( p < end );
769  }
770  else {
771  // dec
772  if ( p == end )
773  ThrowError(fFormatError, "invalid char reference");
774  do {
775  c = *p++;
776  if ( c >= '0' && c <= '9' )
777  v = v * 10 + (c - '0');
778  else
780  "invalid symbol in char reference");
781  } while ( p < end );
782  }
783  return v;
784  }
785  else {
786  CTempString e(p, offset);
787  if ( e == "lt" )
788  return '<';
789  if ( e == "gt" )
790  return '>';
791  if ( e == "amp" )
792  return '&';
793  if ( e == "apos" )
794  return '\'';
795  if ( e == "quot" )
796  return '"';
797  ThrowError(fFormatError, "unknown entity name: " + string(e));
798  }
799  }
800  else if ( c == endingChar ) {
801  return -1;
802  }
803  m_Input.SkipChar();
804  return c & 0xFF;
805 }
806 
807 /*
808 In XML 1.1, almost all chars are allowed:
809 http://www.w3.org/TR/xml11/#NT-Char
810 BUT, we declare this as xml 1.0:
811  CObjectOStreamXml::WriteFileHeader
812 Once so, some chars are not allowed
813 http://www.w3.org/TR/xml/#charsets
814 
815 */
816 inline bool BAD_CHAR(int x) {
817  return (x < 0x20 && x > 0x0 && x != 0x9 && x != 0xA && x != 0xD);
818 }
820  return BAD_CHAR(x) ?
822 }
823 inline
824 int CObjectIStreamXml::ReadEncodedChar(char endingChar, EStringType type, bool& encoded)
825 {
826  return x_VerifyChar(x_ReadEncodedChar(endingChar,type,encoded));
827 }
828 
829 int CObjectIStreamXml::x_ReadEncodedChar(char endingChar, EStringType type, bool& encoded)
830 {
833 
834  if (enc_out == eEncoding_UTF8 &&
835  !m_Utf8Buf.empty() && m_Utf8Pos != m_Utf8Buf.end()) {
836  if (++m_Utf8Pos != m_Utf8Buf.end()) {
837  return *m_Utf8Pos & 0xFF;
838  } else {
839  m_Utf8Buf.clear();
840  }
841  }
842  int c = ReadEscapedChar(endingChar, &encoded);
843  if (c < 0) {
844  return c;
845  }
846  if (enc_out != eEncoding_Unknown) {
847  if (encoded) {
848  TUnicodeSymbol chU = c;
849  if (enc_out == eEncoding_UTF8) {
850  m_Utf8Buf = CUtf8::AsUTF8( &chU, 1);
851  m_Utf8Pos = m_Utf8Buf.begin();
852  return *m_Utf8Pos & 0xFF;
853  } else {
854  return CUtf8::SymbolToChar( chU, enc_out);
855  }
856  }
857  if (enc_in != enc_out) {
858  if (enc_out != eEncoding_UTF8) {
859  TUnicodeSymbol chU = enc_in == eEncoding_UTF8 ?
860  ReadUtf8Char((char)c) : CUtf8::CharToSymbol((char)c, enc_in);
861  Uint1 ch = CUtf8::SymbolToChar( chU, enc_out);
862  return ch & 0xFF;
863  }
864  if ((c & 0x80) == 0) {
865  return c;
866  }
867  char ch = (char)c;
868  m_Utf8Buf = CUtf8::AsUTF8( CTempString(&ch,1), enc_in);
869  m_Utf8Pos = m_Utf8Buf.begin();
870  return *m_Utf8Pos & 0xFF;
871  }
872  }
873  return c;
874 }
875 
877 {
878  size_t more = 0;
879  TUnicodeSymbol chU = CUtf8::DecodeFirst(c, more);
880  while (chU && more--) {
881  chU = CUtf8::DecodeNext(chU, m_Input.GetChar());
882  }
883  if (chU == 0) {
884  ThrowError(fInvalidData, "invalid UTF8 string");
885  }
886  return chU;
887 }
888 
890 {
891  if ( OutsideTag() )
892  ThrowError(fFormatError, "attribute expected");
893  return ReadName(SkipWS());
894 }
895 
896 void CObjectIStreamXml::ReadAttributeValue(string& value, bool skipClosing)
897 {
898  if ( SkipWS() != '=' )
899  ThrowError(fFormatError, "'=' expected");
900  m_Input.SkipChar(); // '='
901  char startChar = SkipWS();
902  if ( startChar != '\'' && startChar != '\"' )
903  ThrowError(fFormatError, "attribute value must start with ' or \"");
904  m_Input.SkipChar();
905  bool encoded = false;
906  for ( ;; ) {
907  int c = ReadEncodedChar(startChar,eStringTypeUTF8,encoded);
908  if ( c < 0 )
909  break;
910  if (c != 0) {
911  value += char(c);
912  }
913  }
914  if (!m_Attlist || skipClosing) {
915  m_Input.SkipChar();
916  }
917 }
918 
920 {
921  char c;
922  m_Attlist = true;
923  for (;;) {
924  c = SkipWS();
925  if (IsEndOfTagChar(c)) {
926  m_Attlist = false;
927  break;
928  }
929  CTempString tagName = ReadName(c);
930  if (!tagName.empty()) {
931  string value;
932  ReadAttributeValue(value, true);
933  }
934  }
935  return c;
936 }
937 
939 {
940  CTempString attr;
941 // accept both <a>true</a> and <a value="true"/>
942 // for compatibility with ASN-generated classes
943  string sValue;
944  bool haveattr=false;
945  if (!m_Attlist) {
946  while (HasAttlist()) {
947  attr = ReadAttributeName();
948  if ( attr == "value" ) {
949  ReadAttributeValue(sValue);
950  haveattr = true;
951  continue;
952  }
953  if ( attr == "nil") {
954  m_IsNil = true;
955  }
956  string value;
958  }
959  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
960  return x_UseMemberDefault<bool>();
961  }
962  }
963  if (!haveattr) {
964  ReadWord(sValue);
965  }
967 
968 // http://www.w3.org/TR/xmlschema11-2/#boolean
969  bool value;
970  if ( sValue == "true" || sValue == "1")
971  value = true;
972  else {
973  if ( sValue != "false" && sValue != "0") {
975  "'true' or 'false' value expected: "+sValue);
976  }
977  value = false;
978  }
980  ThrowError(fFormatError, "boolean tag must have empty contents");
981  return value;
982 }
983 
985 {
986  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
987  return x_UseMemberDefault<char>();
988  }
989  BeginData();
990  int c = ReadEscapedChar('<');
991  if ( c < 0 || m_Input.PeekChar() != '<' )
992  ThrowError(fFormatError, "one char tag content expected");
993  return (char)c;
994 }
995 
997 {
998  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
999  return x_UseMemberDefault<Int4>();
1000  }
1001  BeginData();
1002  return m_Input.GetInt4();
1003 }
1004 
1006 {
1007  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
1008  return x_UseMemberDefault<Uint4>();
1009  }
1010  BeginData();
1011  return m_Input.GetUint4();
1012 }
1013 
1015 {
1016  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
1017  return x_UseMemberDefault<Int8>();
1018  }
1019  BeginData();
1020  return m_Input.GetInt8();
1021 }
1022 
1024 {
1025  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
1026  return x_UseMemberDefault<Uint8>();
1027  }
1028  BeginData();
1029  return m_Input.GetUint8();
1030 }
1031 
1033 {
1034  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
1035  return x_UseMemberDefault<double>();
1036  }
1037  string s;
1038  ReadWord(s);
1039  char* endptr;
1040  double result = NStr::StringToDoublePosix(s.c_str(), &endptr, NStr::fDecimalPosixFinite);
1041  while (IsWhiteSpace(*endptr)) {
1042  ++endptr;
1043  }
1044  if ( *endptr != 0 )
1045  ThrowError(fFormatError, "invalid float number");
1046  return result;
1047 }
1048 
1050 {
1052  ThrowError(fFormatError, "empty tag expected");
1053 }
1054 
1055 bool CObjectIStreamXml::ReadAnyContent(const string& ns_prefix, string& value)
1056 {
1057  if (ThisTagIsSelfClosed()) {
1058  EndSelfClosedTag();
1059  return false;
1060  }
1061  while (!NextTagIsClosing()) {
1062  while (NextIsTag()) {
1063  string tagAny;
1064  tagAny = ReadName(BeginOpeningTag());
1065  value += '<';
1066  value += tagAny;
1067  while (HasAttlist()) {
1068  string attribName = ReadName(SkipWS());
1069  if (attribName.empty()) {
1070  break;
1071  }
1072  if (m_CurrNsPrefix.empty() || m_CurrNsPrefix == ns_prefix) {
1073  value += " ";
1074  value += attribName;
1075  value += "=\"";
1076  string attribValue;
1077  ReadAttributeValue(attribValue, true);
1078  value += attribValue;
1079  value += "\"";
1080  } else {
1081  // skip attrib from different namespaces
1082  string attribValue;
1083  ReadAttributeValue(attribValue, true);
1084  }
1085  }
1086  string value2;
1087  if (ReadAnyContent(ns_prefix, value2)) {
1088  CloseTag(tagAny);
1089  }
1090  if (value2.empty()) {
1091  value += "/>";
1092  } else {
1093  value += '>';
1094  value += value2;
1095  value += "</";
1096  value += tagAny;
1097  value += '>';
1098  }
1099  }
1100  string data;
1102  value += data;
1103  }
1104  return true;
1105 }
1106 
1108 {
1109  obj.Reset();
1110  string tagName;
1111  if (!m_RejectedTag.empty()) {
1112  tagName = RejectedName();
1113  obj.SetName( tagName);
1114  } else if (!StackIsEmpty() && TopFrame().HasMemberId()) {
1115  obj.SetName( TopFrame().GetMemberId().GetName());
1116  }
1117  string ns_prefix(m_CurrNsPrefix);
1118 
1119  BEGIN_OBJECT_FRAME(eFrameOther);
1120  while (HasAttlist()) {
1121  string attribName = ReadName(SkipWS());
1122  if (attribName.empty()) {
1123  break;
1124  }
1125  string value;
1126  ReadAttributeValue(value, true);
1127  if (attribName == "xmlns") {
1128  m_NsPrefixToName[ns_prefix] = value;
1129  m_NsNameToPrefix[value] = ns_prefix;
1130  } else {
1132  }
1133  }
1134  obj.SetNamespacePrefix(ns_prefix);
1135  obj.SetNamespaceName(m_NsPrefixToName[ns_prefix]);
1136  string value;
1137  if (ReadAnyContent(ns_prefix,value) && !tagName.empty()) {
1138  CloseTag(tagName);
1139  }
1141  END_OBJECT_FRAME();
1142 }
1143 
1145 {
1146  if (SelfClosedTag() || ThisTagIsSelfClosed()) {
1147  //EndSelfClosedTag();
1148  return true;
1149  }
1150  if ( m_Attlist && InsideOpeningTag() ) {
1152  m_Attlist = true;
1153  return true;
1154  }
1155  while (!NextTagIsClosing()) {
1156  while (NextIsTag()) {
1157  string tagName = ReadName(BeginOpeningTag());
1158  if (SkipAnyContent()) {
1159  CloseTag(tagName);
1160  }
1161  }
1162  string data;
1163  ReadTagData(data);
1164  }
1165  return true;
1166 }
1167 
1169 {
1170  string tagName;
1171  if (!m_RejectedTag.empty()) {
1172  tagName = RejectedName();
1173  } else if (OutsideTag()) {
1174  tagName = ReadName(BeginOpeningTag());
1175  }
1176  if (SkipAnyContent() && !tagName.empty()) {
1177  CloseTag(tagName);
1178  }
1179 }
1180 
1182 {
1183  obj.clear();
1184 #if BITSTRING_AS_VECTOR
1185  if (EndOpeningTagSelfClosed()) {
1186  return;
1187  }
1188  BeginData();
1189  size_t reserve;
1190  const size_t step=128;
1191  obj.reserve( reserve=step );
1192  for (int c= GetHexChar(); c >= 0; c= GetHexChar()) {
1193  Uint1 byte = c;
1194  for (Uint1 mask= 0x8; mask != 0; mask >>= 1) {
1195  obj.push_back( (byte & mask) != 0 );
1196  if (--reserve == 0) {
1197  obj.reserve(obj.size() + (reserve=step));
1198  }
1199  }
1200  }
1201  obj.reserve(obj.size());
1202 #else
1203  obj.resize(0);
1204  if (EndOpeningTagSelfClosed()) {
1205  return;
1206  }
1207  if (IsCompressed()) {
1209  return;
1210  }
1211  BeginData();
1213  for ( ;; ++len) {
1214  char c = m_Input.GetChar();
1215  if (c == '1') {
1216  obj.resize(len+1);
1217  obj.set_bit(len);
1218  } else if (c != '0') {
1219  if (IsWhiteSpace(c)) {
1220  --len;
1221  continue;
1222  }
1223  m_Input.UngetChar(c);
1224  if ( c == '<' )
1225  break;
1226  ThrowError(fFormatError, "invalid char in bit string");
1227  }
1228  }
1229  obj.resize(len);
1230 #endif
1231 }
1232 
1234 {
1235  SkipByteBlock();
1236 }
1237 
1239 {
1240  str.erase();
1241  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
1243  CStringUTF8 u( CUtf8::AsUTF8(x_UseMemberDefault<string>(),enc_in));
1245  str = u;
1246  } else {
1248  }
1249  return;
1250  }
1251  if (EndOpeningTagSelfClosed()) {
1252  return;
1253  }
1254 #if 0
1255  if (TopFrame().GetNotag()) {
1256  ReadWord(str, type);
1257  } else {
1258  ReadTagData(str, type);
1259  }
1260 #else
1261  ReadTagData(str, type);
1262 #endif
1263 }
1264 
1266 {
1267  if ( EndOpeningTagSelfClosed() ) {
1268  // null pointer string
1269  return 0;
1270  }
1271  string str;
1272  ReadTagData(str);
1273  return NcbiSysChar_strdup(str.c_str());
1274 }
1275 
1277 // http://www.w3.org/TR/2000/REC-xml-20001006#dt-cdsection
1278 // must begin with <![CDATA[
1279 // must end with ]]>
1280 {
1281  if (m_Input.PeekChar() != '<' || m_Input.PeekChar(1) != '!') {
1282  return false;
1283  }
1284  m_Input.SkipChars(2);
1285  const char* open = "[CDATA[";
1286  for ( ; *open; ++open) {
1287  if (m_Input.PeekChar() != *open) {
1288  ThrowError(fFormatError, "CDATA section expected");
1289  }
1290  m_Input.SkipChar();
1291  }
1292  while ( m_Input.PeekChar(0) != ']' ||
1293  m_Input.PeekChar(1) != ']' ||
1294  m_Input.PeekChar(2) != '>') {
1295  str += m_Input.PeekChar();
1296  m_Input.SkipChar();
1297  }
1298  m_Input.SkipChars(3);
1299  return true;
1300 }
1301 
1303 /*
1304  White Space Handling:
1305  https://www.w3.org/TR/xml/#sec-white-space
1306  https://www.w3.org/TR/xml11/#sec-white-space
1307 
1308  End-of-Line Handling
1309  https://www.w3.org/TR/xml/#sec-line-ends
1310  https://www.w3.org/TR/xml11/#sec-line-ends
1311 
1312  Attribute-Value Normalization
1313  https://www.w3.org/TR/xml/#AVNormalize
1314  https://www.w3.org/TR/xml11/#AVNormalize
1315 */
1316 {
1317  if (m_LeadingWs != 0) {
1318  str.append(m_LeadingWs, ' ');
1319  m_LeadingWs = 0;
1320  }
1321  BeginData();
1322  bool encoded = false;
1323  bool CR = false;
1324  try {
1325  for ( ;; ) {
1326  int c = ReadEncodedChar(m_Attlist ? '\"' : '<', type, encoded);
1327  if ( c < 0 ) {
1328  if (m_Attlist || !ReadCDSection(str)) {
1329  break;
1330  }
1331  CR = false;
1332  continue;
1333  }
1334  if (c == 0) {
1335  continue;
1336  }
1337  if (CR) {
1338  if (c == '\n') {
1339  CR = false;
1340  } else if (c == '\r') {
1341  c = '\n';
1342  }
1343  } else if (c == '\r') {
1344  CR = true;
1345  continue;
1346  }
1347  if (m_Attlist && !encoded && IsWhiteSpace((char)c)) {
1348  c = ' ';
1349  }
1350  str += (char)c;
1351  // pre-allocate memory for long strings
1352  if ( str.size() > 128 && (double)str.capacity()/((double)str.size()+1.0) < 1.1 ) {
1353  str.reserve(str.size()*2);
1354  }
1355  }
1356  } catch (CEofException&) {
1357  }
1358  str.reserve(str.size());
1359 }
1360 
1362 {
1363  BeginData();
1364  bool encoded = false;
1365  SkipWS();
1366  try {
1367  for ( ;; ) {
1368  int c = ReadEncodedChar(m_Attlist ? '\"' : '<', type, encoded);
1369  if ( c < 0 || IsWhiteSpace((char)c)) {
1370  break;
1371  }
1372  if (c != 0) {
1373  str += (char)c;
1374  }
1375  }
1376  } catch (CEofException&) {
1377  }
1378  str.reserve(str.size());
1379 }
1380 
1382 {
1384  bool valueonly = m_StdXml;
1385  if (valueonly) {
1386  if (values.IsInteger()) {
1387  value = ReadInt4();
1388  } else {
1389  string str;
1390  ReadString(str);
1391  value = values.FindValue( str);
1392  }
1393  return value;
1394  }
1395  const string& enumName = values.GetName();
1396  if ( !m_SkipNextTag && !enumName.empty() ) {
1397  // global enum
1398  OpenTag(enumName);
1400  }
1401  if ( InsideOpeningTag() ) {
1402  // try to read attribute 'value'
1403  if ( IsEndOfTagChar( SkipWS()) ) {
1404  // no attribute
1405  if ( !values.IsInteger() )
1406  ThrowError(fFormatError, "attribute 'value' expected");
1407  m_Input.SkipChar();
1408  Found_gt();
1409  BeginData();
1410  value = m_Input.GetInt4();
1411  }
1412  else {
1413  if (m_Attlist) {
1414  string valueName;
1415  ReadAttributeValue(valueName);
1416  NStr::TruncateSpacesInPlace(valueName);
1417  value = values.FindValue(valueName);
1418  } else {
1419  CTempString attr;
1420  while (HasAttlist()) {
1421  attr = ReadAttributeName();
1422  if ( attr == "value" ) {
1423  break;
1424  }
1425  string value_tmp;
1426  ReadAttributeValue(value_tmp);
1427  }
1428  if ( attr != "value" ) {
1430  ThrowError(fMissingValue,"attribute 'value' is missing");
1431  }
1432  string valueName;
1433  ReadAttributeValue(valueName);
1434  NStr::TruncateSpacesInPlace(valueName);
1435  value = values.FindValue(valueName);
1436  if ( !EndOpeningTagSelfClosed() && values.IsInteger() ) {
1437  // read integer value
1439  if ( value != m_Input.GetInt4() )
1441  "incompatible name and value of named integer");
1442  }
1443  }
1444  }
1445  }
1446  else {
1447  // outside of tag
1448  if ( !values.IsInteger() )
1449  ThrowError(fFormatError, "attribute 'value' expected");
1450  BeginData();
1451  value = m_Input.GetInt4();
1452  }
1453  if ( !m_SkipNextTag && !enumName.empty() ) {
1454  // global enum
1455  CloseTag(enumName);
1456  }
1457  return value;
1458 }
1459 
1461 {
1463  if (m_IsNil) {
1464  m_IsNil=false;
1466  return eNullPointer;
1467  }
1468  }
1470  // self closed tag
1471  return eNullPointer;
1472  }
1473  return eThisPointer;
1474 }
1475 
1477 {
1478  ThrowError(fNotImplemented, "Not Implemented");
1479  return 0;
1480 /*
1481  CTempString attr = ReadAttributeName();
1482  if ( attr != "index" )
1483  ThrowError(fIllegalCall, "attribute 'index' expected");
1484  string index;
1485  ReadAttributeValue(index);
1486  EndOpeningTagSelfClosed();
1487  return NStr::StringToInt(index);
1488 */
1489 }
1490 
1492 {
1493  ThrowError(fNotImplemented, "Not Implemented");
1494  return NcbiEmptyString;
1495 }
1496 
1498 {
1499  BeginData();
1501  if (!m_RejectedTag.empty()) {
1504  }
1505 }
1506 
1508 {
1509  _ASSERT(OutsideTag());
1511 }
1512 
1514  const char* str, size_t length)
1515 {
1516  if ( tag.size() < length ||
1517  memcmp(tag.data(), str, length) != 0 )
1518  ThrowError(fFormatError, "invalid tag name: "+string(tag));
1519  return CTempString(tag.data() + length, tag.size() - length);
1520 }
1521 
1523  size_t level)
1524 {
1525  const TFrame& frame = FetchFrameFromTop(level);
1526  switch ( frame.GetFrameType() ) {
1527  case TFrame::eFrameNamed:
1528  case TFrame::eFrameArray:
1529  case TFrame::eFrameClass:
1530  case TFrame::eFrameChoice:
1531  {
1532  const string& name = frame.GetTypeInfo()->GetName();
1533  if ( !name.empty() )
1534  return SkipTagName(tag, name);
1535  else
1536  return SkipStackTagName(tag, level + 1);
1537  }
1540  {
1541  tag = SkipStackTagName(tag, level + 1, '_');
1542  return SkipTagName(tag, frame.GetMemberId().GetName());
1543  }
1545  {
1546  if (GetStackDepth() > level+1) {
1547  tag = SkipStackTagName(tag, level + 1);
1548  return SkipTagName(tag, "_E");
1549  }
1550  return CTempString();
1551  }
1552  default:
1553  break;
1554  }
1555  ThrowError(fIllegalCall, "illegal frame type");
1556  return tag;
1557 }
1558 
1560  size_t level, char c)
1561 {
1562  tag = SkipStackTagName(tag, level);
1563  if ( tag.empty() || tag[0] != c )
1564  ThrowError(fFormatError, "invalid tag name: "+string(tag));
1565  return CTempString(tag.data() + 1, tag.size() - 1);
1566 }
1567 
1568 void CObjectIStreamXml::OpenTag(const string& e)
1569 {
1570  CTempString tagName;
1571  if (m_RejectedTag.empty()) {
1572  tagName = ReadName(BeginOpeningTag());
1573  } else {
1574  tagName = RejectedName();
1575  }
1576  if ( tagName != e )
1577  ThrowError(fFormatError, "tag '"+e+"' expected: "+string(tagName));
1578 }
1579 
1580 void CObjectIStreamXml::CloseTag(const string& e)
1581 {
1582  if ( SelfClosedTag() ) {
1583  EndSelfClosedTag();
1584  }
1585  else {
1586  CTempString tagName = ReadName(BeginClosingTag());
1587  if ( tagName != e )
1588  ThrowError(fFormatError, "tag '"+e+"' expected: "+string(tagName));
1589  EndClosingTag();
1590  }
1591 }
1592 
1594 {
1595  CTempString tagName;
1596  if (m_RejectedTag.empty()) {
1597  tagName = ReadName(BeginOpeningTag());
1598  if (!x_IsStdXml()) {
1599  CTempString rest = SkipStackTagName(tagName, level);
1600  if ( !rest.empty() )
1602  "unexpected tag: "+string(tagName)+string(rest));
1603  }
1604  } else {
1605  tagName = RejectedName();
1606  }
1607 }
1608 
1610 {
1611  if ( SelfClosedTag() ) {
1612  EndSelfClosedTag();
1613  }
1614  else {
1615  if (m_Attlist) {
1617  } else {
1618  CTempString tagName = ReadName(BeginClosingTag());
1619  if (!x_IsStdXml()) {
1620  CTempString rest = SkipStackTagName(tagName, level);
1621  if ( !rest.empty() )
1623  "unexpected tag: "+string(tagName)+string(rest));
1624  }
1625  }
1626  EndClosingTag();
1627  }
1628 }
1629 
1631 {
1632  if ( !type->GetName().empty() ) {
1633  OpenTag(type->GetName());
1634  }
1635 }
1636 
1638 {
1639  if ( !type->GetName().empty() )
1640  CloseTag(type->GetName());
1641 }
1642 
1644 {
1645  while ( elementType->GetName().empty() ) {
1646  if ( elementType->GetTypeFamily() != eTypeFamilyPointer )
1647  return false;
1649  elementType)->GetPointedType();
1650  }
1651  // found named type
1652  return true;
1653 }
1654 
1656 {
1657  if (InsideTag()) {
1658  return !IsEndOfTagChar( SkipWS() );
1659  }
1660  return false;
1661 }
1662 
1664 {
1665  BeginData();
1666  return SkipWSAndComments() == '<' &&
1667  m_Input.PeekChar(1) != '/' &&
1668  m_Input.PeekChar(1) != '!';
1669 }
1670 
1672 {
1673  BeginData();
1674  return SkipWSAndComments() == '<' && m_Input.PeekChar(1) == '/';
1675 }
1676 
1678 {
1679  if (InsideOpeningTag()) {
1680  return EndOpeningTagSelfClosed();
1681  }
1682  return SelfClosedTag();
1683 }
1684 
1685 
1686 void
1688 {
1689  if (!m_StdXml) {
1690  if (TopFrame().GetFrameType() == CObjectStackFrame::eFrameArray &&
1691  FetchFrameFromTop(1).GetFrameType() == CObjectStackFrame::eFrameNamed) {
1692  const CClassTypeInfo* clType =
1693  dynamic_cast<const CClassTypeInfo*>(FetchFrameFromTop(1).GetTypeInfo());
1694  if (clType && clType->Implicit()) {
1695  TopFrame().SetNotag();
1696  return;
1697  }
1698  }
1699  OpenTagIfNamed(containerType);
1700  }
1701 }
1702 
1704 {
1705  if (!m_StdXml && !TopFrame().GetNotag()) {
1706  CloseTagIfNamed(TopFrame().GetTypeInfo());
1707  }
1708 }
1709 
1711 {
1712  if (!HasMoreElements(elementType)) {
1713  return false;
1714  }
1715  if ( !WillHaveName(elementType) ) {
1716  BeginArrayElement(elementType);
1717  }
1718  return true;
1719 }
1720 
1722 {
1723  if ( !WillHaveName(TopFrame().GetTypeInfo()) ) {
1724  EndArrayElement();
1725  }
1726 }
1727 
1729 {
1730  const CItemsInfo& items = classType->GetItems();
1731  TMemberIndex i = (pos != kInvalidMember ? pos : items.FirstIndex());
1732  for (; i <= items.LastIndex(); ++i) {
1733  const CItemInfo* itemInfo = items.GetItemInfo( i );
1734  if (itemInfo->GetId().HasAnyContent()) {
1735  return i;
1736  }
1737  if (itemInfo->GetId().HasNotag()) {
1738  if (itemInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyContainer) {
1740  if (elem.GetTypeFamily() == eTypeFamilyPointer) {
1741  elem = elem.GetPointedType();
1742  }
1743  if (elem.GetTypeFamily() == eTypeFamilyPrimitive &&
1745  return i;
1746  }
1747  }
1748  }
1749  }
1750 /*
1751  if (items.Size() == 1) {
1752  const CItemInfo* itemInfo = items.GetItemInfo( items.FirstIndex() );
1753  if (itemInfo->GetId().HasNotag()) {
1754  if (itemInfo->GetTypeInfo()->GetTypeFamily() == eTypeFamilyContainer) {
1755  CObjectTypeInfo elem = CObjectTypeInfo(itemInfo->GetTypeInfo()).GetElementType();
1756  if (elem.GetTypeFamily() == eTypeFamilyPointer) {
1757  elem = elem.GetPointedType();
1758  }
1759  if (elem.GetTypeFamily() == eTypeFamilyPrimitive &&
1760  elem.GetPrimitiveValueType() == ePrimitiveValueAny) {
1761  return items.FirstIndex();
1762  }
1763  }
1764  }
1765  }
1766 */
1767  return kInvalidMember;
1768 }
1769 
1771 {
1772  bool no_more=false;
1773  try {
1774  no_more = ThisTagIsSelfClosed() || NextTagIsClosing();
1775  } catch (CEofException&) {
1776  no_more = true;
1777  }
1778  if (no_more) {
1779  m_LastPrimitive.erase();
1780  return false;
1781  }
1782  if (x_IsStdXml()) {
1783  CTempString tagName;
1784  TTypeInfo type = GetRealTypeInfo(elementType);
1785  // this is to handle STL containers of primitive types
1787  if (m_SkipNextTag) {
1788  return true;
1789  } else if (!m_RejectedTag.empty()) {
1791  return true;
1792  } else {
1793  tagName = ReadName(BeginOpeningTag());
1794  UndoClassMember();
1795  bool res = (m_LastPrimitive.empty() ||
1796  tagName == m_LastPrimitive || tagName == type->GetName() ||
1798  if (!res) {
1799  m_LastPrimitive.erase();
1800  }
1801  return res;
1802  }
1803  }
1804  const CClassTypeInfoBase* classType =
1805  dynamic_cast<const CClassTypeInfoBase*>(type);
1806  const CAliasTypeInfo* aliasType = classType ? NULL :
1807  dynamic_cast<const CAliasTypeInfo*>(type);
1808  if (aliasType && aliasType->IsFullAlias()) {
1809  classType = dynamic_cast<const CClassTypeInfoBase*>(GetRealTypeInfo(aliasType));
1810  }
1811  if (classType || aliasType) {
1812  if (m_RejectedTag.empty()) {
1813  if (!NextIsTag()) {
1814  return true;
1815  }
1816  tagName = ReadName(BeginOpeningTag());
1817  } else {
1818  tagName = RejectedName();
1819  }
1820  UndoClassMember();
1821 
1822  if (classType && classType->GetName().empty()) {
1823  return classType->GetItems().FindDeep(tagName) != kInvalidMember ||
1824  HasAnyContent(classType) != kInvalidMember;
1825  }
1826  return (classType && tagName == classType->GetName()) || (aliasType && tagName == aliasType->GetName());
1827  }
1828  }
1829  return true;
1830 }
1831 
1832 
1834  const CTempString& name) const
1835 {
1836  for (;;) {
1837  if (type->GetTypeFamily() == eTypeFamilyContainer) {
1838  const CContainerTypeInfo* cont =
1839  dynamic_cast<const CContainerTypeInfo*>(type);
1840  if (cont) {
1841  type = cont->GetElementType();
1842  }
1843  } else if (type->GetTypeFamily() == eTypeFamilyPointer) {
1844  const CPointerTypeInfo* ptr =
1845  dynamic_cast<const CPointerTypeInfo*>(type);
1846  if (ptr) {
1847  type = ptr->GetPointedType();
1848  }
1849  } else {
1850  break;
1851  }
1852  }
1853  const CClassTypeInfoBase* classType =
1854  dynamic_cast<const CClassTypeInfoBase*>(type);
1855  if (classType) {
1856  TMemberIndex i = classType->GetItems().FindDeep(name);
1857  if (i != kInvalidMember) {
1858  return i;
1859  }
1860  }
1861  return kInvalidMember;
1862 }
1863 
1864 #ifdef VIRTUAL_MID_LEVEL_IO
1865 void CObjectIStreamXml::ReadContainer(const CContainerTypeInfo* containerType,
1866  TObjectPtr containerPtr)
1867 {
1868  if ( m_StdXml || containerType->GetName().empty() ) {
1869  ReadContainerContents(containerType, containerPtr);
1870  }
1871  else {
1872  BEGIN_OBJECT_FRAME2(eFrameArray, containerType);
1873  OpenTag(containerType);
1874 
1875  ReadContainerContents(containerType, containerPtr);
1876 
1877  CloseTag(containerType);
1878  END_OBJECT_FRAME();
1879  }
1880 }
1881 
1882 void CObjectIStreamXml::SkipContainer(const CContainerTypeInfo* containerType)
1883 {
1884  if ( m_StdXml || containerType->GetName().empty() ) {
1885  SkipContainerContents(containerType);
1886  }
1887  else {
1888  BEGIN_OBJECT_FRAME2(eFrameArray, containerType);
1889  OpenTag(containerType);
1890 
1891  SkipContainerContents(containerType);
1892 
1893  CloseTag(containerType);
1894  END_OBJECT_FRAME();
1895  }
1896 }
1897 #endif
1898 
1899 
1901 {
1902  if (x_IsStdXml()) {
1903  CObjectTypeInfo type(GetRealTypeInfo(elementType));
1904  if (type.GetTypeFamily() != eTypeFamilyPrimitive ||
1905  type.GetPrimitiveValueType() == ePrimitiveValueAny) {
1906  TopFrame().SetNotag();
1907  return;
1908  }
1909  if (m_SkipNextTag && type.GetTypeFamily() == eTypeFamilyPrimitive) {
1910  TopFrame().SetNotag();
1911  return;
1912  }
1913  }
1914  OpenStackTag(0);
1915 }
1916 
1918 {
1919  if (TopFrame().GetNotag()) {
1920  TopFrame().SetNotag(false);
1921  } else {
1922  CloseStackTag(0);
1923  }
1924 }
1925 
1927  TObjectPtr containerPtr)
1928 {
1929  int count = 0;
1930  TTypeInfo elementType = cType->GetElementType();
1931  if ( !WillHaveName(elementType) ) {
1932  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
1933 
1935  bool old_element = cType->InitIterator(iter, containerPtr);
1936  while ( HasMoreElements(elementType) ) {
1937  BeginArrayElement(elementType);
1938  do {
1939  if ( old_element ) {
1940  elementType->ReadData(*this, cType->GetElementPtr(iter));
1941  old_element = cType->NextElement(iter);
1942  }
1943  else {
1944  cType->AddElement(containerPtr, *this);
1945  }
1946  } while (!m_RejectedTag.empty() &&
1947  FindDeep(elementType,m_RejectedTag) != kInvalidMember);
1948  EndArrayElement();
1949  ++count;
1950  }
1951  if ( old_element ) {
1952  cType->EraseAllElements(iter);
1953  }
1954 
1955  END_OBJECT_FRAME();
1956  }
1957  else {
1959  bool old_element = cType->InitIterator(iter, containerPtr);
1960  while ( HasMoreElements(elementType) ) {
1961  if ( old_element ) {
1962  elementType->ReadData(*this, cType->GetElementPtr(iter));
1963  old_element = cType->NextElement(iter);
1964  }
1965  else {
1966  cType->AddElement(containerPtr, *this);
1967  }
1968  ++count;
1969  }
1970  if ( old_element ) {
1971  cType->EraseAllElements(iter);
1972  }
1973  }
1974  if (count == 0) {
1975  const TFrame& frame = FetchFrameFromTop(0);
1977  const CClassTypeInfo* clType =
1978  dynamic_cast<const CClassTypeInfo*>(frame.GetTypeInfo());
1979  if (clType && clType->Implicit() && clType->IsImplicitNonEmpty()) {
1980  ThrowError(fFormatError, "container is empty");
1981  }
1982  }
1983  }
1984 }
1985 
1987 {
1988  TTypeInfo elementType = cType->GetElementType();
1989  if ( !WillHaveName(elementType) ) {
1990  BEGIN_OBJECT_FRAME2(eFrameArrayElement, elementType);
1991 
1992  while ( HasMoreElements(elementType) ) {
1993  BeginArrayElement(elementType);
1994  SkipObject(elementType);
1995  EndArrayElement();
1996  }
1997 
1998  END_OBJECT_FRAME();
1999  }
2000  else {
2001  while ( HasMoreElements(elementType) ) {
2002  SkipObject(elementType);
2003  }
2004  }
2005 }
2006 
2008 {
2009  CheckStdXml(namedTypeInfo);
2010  if (m_SkipNextTag || namedTypeInfo->GetName().empty()) {
2011  TopFrame().SetNotag();
2012  m_SkipNextTag = false;
2013  } else {
2014  TTypeInfo realtype = GetRealTypeInfo(namedTypeInfo);
2015  if (realtype->GetTypeFamily() == eTypeFamilyPrimitive &&
2016  GetStackDepth() > 2 && m_StdXml) {
2017  TopFrame().SetNotag();
2018  m_SkipNextTag = false;
2019  return;
2020  }
2021  OpenTag(namedTypeInfo);
2022  }
2023  const CAliasTypeInfo* aliasType =
2024  dynamic_cast<const CAliasTypeInfo*>(namedTypeInfo);
2025  if (aliasType) {
2026  m_SkipNextTag = aliasType->IsFullAlias();
2027  }
2028  else if (m_StdXml) {
2029  const CClassTypeInfo* classType = dynamic_cast<const CClassTypeInfo*>(namedTypeInfo);
2030  m_SkipNextTag = (classType && classType->Implicit());
2031  }
2032 }
2033 
2035 {
2036  m_SkipNextTag = false;
2037  if (TopFrame().GetNotag()) {
2038  TopFrame().SetNotag(false);
2039  return;
2040  }
2041  CloseTag(TopFrame().GetTypeInfo()->GetName());
2042 }
2043 
2044 #ifdef VIRTUAL_MID_LEVEL_IO
2045 
2046 void CObjectIStreamXml::ReadNamedType(TTypeInfo namedTypeInfo,
2047  TTypeInfo typeInfo,
2048  TObjectPtr object)
2049 {
2050  BEGIN_OBJECT_FRAME2(eFrameNamed, namedTypeInfo);
2051 
2052  BeginNamedType(namedTypeInfo);
2053  ReadObject(object, typeInfo);
2054  EndNamedType();
2055 
2056  END_OBJECT_FRAME();
2057 }
2058 #endif
2059 
2061 {
2062  if (typeinfo->GetCodeVersion() > 21600) {
2063  m_StdXml = typeinfo->GetDataSpec() != EDataSpec::eASN;
2064  } else {
2065  const CClassTypeInfo* classType =
2066  dynamic_cast<const CClassTypeInfo*>(typeinfo);
2067  if (classType) {
2068  TMemberIndex first = classType->GetItems().FirstIndex();
2069  m_StdXml = classType->GetItems().GetItemInfo(first)->GetId().HaveNoPrefix();
2070  }
2071  }
2072 }
2073 
2075 {
2076  CheckStdXml(classInfo);
2077  if (m_SkipNextTag) {
2078  TopFrame().SetNotag();
2079  m_SkipNextTag = false;
2080  return;
2081  }
2082  if (x_IsStdXml()) {
2083  if (!m_Attlist) {
2084 // if class spec defines no attributes, but there are some - skip them
2085  if (HasAttlist() && !classInfo->GetMemberInfo(
2086  classInfo->GetMembers().FirstIndex())->GetId().IsAttlist()) {
2088  }
2089  }
2090  if (m_Attlist || HasAttlist()) {
2091  TopFrame().SetNotag();
2092  } else {
2093  OpenTagIfNamed(classInfo);
2094  }
2095  } else {
2096  OpenTagIfNamed(classInfo);
2097  }
2098 }
2099 
2101 {
2102  if (TopFrame().GetNotag()) {
2103  TopFrame().SetNotag(false);
2104  } else {
2105  CloseTagIfNamed(TopFrame().GetTypeInfo());
2106  }
2108 }
2109 
2111  const CItemsInfo& items)
2112 {
2113  string message =
2114  "\""+string(id)+"\": unexpected member, should be one of: ";
2115  for ( CItemsInfo::CIterator i(items); i.Valid(); ++i ) {
2116  message += '\"' + items.GetItemInfo(i)->GetId().ToString() + "\" ";
2117  }
2118  ThrowError(fFormatError, message);
2119 }
2120 
2123 {
2124  CTempString tagName;
2125  bool more;
2126  do {
2127  more = false;
2128  if (m_RejectedTag.empty()) {
2129  if (m_Attlist && InsideTag()) {
2130  if (HasAttlist()) {
2131  tagName = ReadName(SkipWS());
2132  } else {
2133  return kInvalidMember;
2134  }
2135  } else {
2136  if (!m_Attlist && InsideOpeningTag()) {
2137  TMemberIndex first = classType->GetMembers().FirstIndex();
2138  if (classType->GetMemberInfo(first)->GetId().IsAttlist()) {
2139  m_Attlist = true;
2140  return first;
2141  }
2142  }
2143  m_Attlist = false;
2144  if ( NextTagIsClosing() )
2145  return kInvalidMember;
2146  tagName = ReadName(BeginOpeningTag());
2147  }
2148  } else {
2149  tagName = RejectedName();
2150  }
2151  TMemberIndex ind = classType->GetMembers().Find(tagName);
2152  if ( ind != kInvalidMember ) {
2153  if (x_IsStdXml()) {
2154  const CMemberInfo *mem_info = classType->GetMemberInfo(ind);
2156  bool needUndo = false;
2157  if (!GetEnforcedStdXml()) {
2158  needUndo = (type != eTypeFamilyPrimitive);
2159  }
2160  if (needUndo) {
2161  TopFrame().SetNotag();
2162  UndoClassMember();
2163  }
2164  return ind;
2165  }
2166  }
2167 // if it is an attribute list, but the tag is unrecognized - just skip it
2168  if (m_Attlist) {
2169  if (ind == kInvalidMember && tagName.empty()) {
2170  return ind;
2171  }
2172  string value;
2174  m_Input.SkipChar();
2175  more = true;
2176  }
2177  } while (more);
2178 
2179  CTempString id = SkipStackTagName(tagName, 1, '_');
2180  TMemberIndex index = classType->GetMembers().Find(id);
2181  if ( index == kInvalidMember ) {
2182  if (CanSkipUnknownMembers()) {
2184  string tag(tagName);
2185  if (SkipAnyContent()) {
2186  CloseTag(tag);
2187  }
2188  return BeginClassMember(classType);
2189  } else {
2190  UnexpectedMember(id, classType->GetMembers());
2191  }
2192  }
2193  return index;
2194 }
2195 
2198  TMemberIndex pos)
2199 {
2200  CTempString tagName;
2201  TMemberIndex first = classType->GetMembers().FirstIndex();
2202  if (m_RejectedTag.empty()) {
2203  if (m_Attlist && InsideTag()) {
2204  if (HasAttlist()) {
2205  for (;;) {
2206  char ch = SkipWS();
2207  if (IsEndOfTagChar(ch)) {
2208  return kInvalidMember;
2209  }
2210  tagName = ReadName(ch);
2211  if (!tagName.empty()) {
2212  if (classType->GetMembers().Find(tagName) != kInvalidMember) {
2213  break;
2214  }
2215  string value;
2216  ReadAttributeValue(value, true);
2217  }
2218  }
2219  } else {
2220  return kInvalidMember;
2221  }
2222  } else {
2223  if (!m_Attlist) {
2224  if (pos == first) {
2225  if (classType->GetMemberInfo(first)->GetId().IsAttlist()) {
2226  m_Attlist = true;
2227  if (m_TagState == eTagOutside) {
2228  m_Input.UngetChar('>');
2230  }
2231  return first;
2232  }
2233 // if class spec defines no attributes, but there are some - skip them
2234  if (HasAttlist()) {
2236  }
2237  }
2238  }
2239  if (m_Attlist && !SelfClosedTag()) {
2240  m_Attlist = false;
2241  TMemberIndex ind = first+1;
2242  if (classType->GetMemberInfo(ind)->GetId().HasNotag()) {
2243  TopFrame().SetNotag();
2244  if (x_IsStdXml() && !GetEnforcedStdXml()) {
2247  }
2248  return ind;
2249  }
2250  if ( NextTagIsClosing() )
2251  return kInvalidMember;
2252 /*
2253  if (!NextIsTag()) {
2254  TMemberIndex ind = first+1;
2255  if (classType->GetMemberInfo(ind)->GetId().HasNotag()) {
2256  TopFrame().SetNotag();
2257  return ind;
2258  }
2259  }
2260 */
2261  }
2262  if ( SelfClosedTag() || ThisTagIsSelfClosed()) {
2263  m_Attlist = false;
2264  TMemberIndex last = classType->GetMembers().LastIndex();
2265  if (pos == last) {
2266  if (classType->GetMemberInfo(pos)->GetId().HasNotag() &&
2267  !classType->GetMemberInfo(pos)->GetId().HasAnyContent()) {
2268  TopFrame().SetNotag();
2269  return pos;
2270  }
2271  }
2272  return kInvalidMember;
2273  }
2274  if ( NextTagIsClosing() )
2275  return kInvalidMember;
2276  if (pos <= classType->GetItems().LastIndex()) {
2277  const CMemberInfo* mem_info = classType->GetMemberInfo(pos);
2278  if (mem_info->GetId().HasNotag() &&
2279  !mem_info->GetId().HasAnyContent()) {
2280  if (GetRealTypeFamily(mem_info->GetTypeInfo()) == eTypeFamilyPrimitive) {
2281  TopFrame().SetNotag();
2282  return pos;
2283  }
2284  }
2285  } else {
2286  if (CanSkipUnknownMembers()) {
2287  while (NextIsTag()) {
2288  tagName = ReadName(BeginOpeningTag());
2289  UndoClassMember();
2290  if (IsKnownElement(tagName)) {
2291  break;
2292  }
2295  }
2296  }
2297  return kInvalidMember;
2298  }
2299  if (!NextIsTag()) {
2300  return kInvalidMember;
2301  }
2302  tagName = ReadName(BeginOpeningTag());
2303  }
2304  } else {
2305  tagName = RejectedName();
2306  }
2307 
2308  TMemberIndex ind = classType->GetMembers().Find(tagName);
2309  if (ind == kInvalidMember) {
2310  ind = classType->GetMembers().FindDeep(tagName, pos);
2311  if (ind != kInvalidMember && ind >= pos) {
2312  TopFrame().SetNotag();
2313  UndoClassMember();
2314  return ind;
2315  }
2316  } else {
2317  const CMemberInfo *mem_info = classType->GetMemberInfo(ind);
2318  if (x_IsStdXml()) {
2320  bool needUndo = false;
2321  if (GetEnforcedStdXml()) {
2322  if (type == eTypeFamilyContainer) {
2323  TTypeInfo mem_type = GetRealTypeInfo(mem_info->GetTypeInfo());
2324  TTypeInfo elem_type = GetContainerElementTypeInfo(mem_type);
2325  needUndo = (elem_type->GetTypeFamily() == eTypeFamilyPrimitive &&
2326  elem_type->GetName() == mem_type->GetName());
2327  }
2328  } else {
2329  needUndo = mem_info->GetId().HasNotag() || mem_info->GetId().HasAnyContent() || type == eTypeFamilyContainer;
2331  }
2332  if (needUndo) {
2333  TopFrame().SetNotag();
2334  UndoClassMember();
2335  }
2336  return ind;
2337  }
2338  }
2339  if (x_IsStdXml()) {
2340  UndoClassMember();
2341  ind = HasAnyContent(classType,pos);
2342  if (ind != kInvalidMember) {
2343  TopFrame().SetNotag();
2344  return ind;
2345  }
2346  if (CanSkipUnknownMembers() &&
2347  pos <= classType->GetMembers().LastIndex()) {
2349  string tag(RejectedName());
2350  if (SkipAnyContent()) {
2351  CloseTag(tag);
2352  }
2353  return BeginClassMember(classType, pos);
2354  }
2355  return kInvalidMember;
2356  }
2357  CTempString id = SkipStackTagName(tagName, 1, '_');
2358  TMemberIndex index = classType->GetMembers().Find(id, pos);
2359  if ( index == kInvalidMember ) {
2360  if (CanSkipUnknownMembers()) {
2362  string tag(tagName);
2363  if (SkipAnyContent()) {
2364  CloseTag(tag);
2365  }
2366  return BeginClassMember(classType, pos);
2367  } else {
2368  UnexpectedMember(id, classType->GetMembers());
2369  }
2370  }
2371  return index;
2372 }
2373 
2375 {
2376  m_SkipNextTag = false;
2377  if (TopFrame().GetNotag()) {
2378  TopFrame().SetNotag(false);
2379  } else {
2380  CloseStackTag(0);
2381  }
2382 }
2383 
2385 {
2386  if (InsideOpeningTag()) {
2389  m_LeadingWs = 0;
2390 #if defined(NCBI_SERIAL_IO_TRACE)
2391  cout << ", Undo= " << m_LastTag;
2392 #endif
2393  }
2394 }
2395 
2397 {
2398  CheckStdXml(choiceType);
2399  if (m_SkipNextTag) {
2400  TopFrame().SetNotag();
2401  m_SkipNextTag = false;
2402  return;
2403  }
2404  OpenTagIfNamed(choiceType);
2405 }
2407 {
2408  if (TopFrame().GetNotag()) {
2409  TopFrame().SetNotag(false);
2410  return;
2411  }
2412  CloseTagIfNamed(TopFrame().GetTypeInfo());
2414 }
2415 
2417 {
2418  CTempString tagName;
2419  TMemberIndex first = choiceType->GetVariants().FirstIndex();
2420  if (m_RejectedTag.empty()) {
2421  if (!m_Attlist) {
2422  if (choiceType->GetVariantInfo(first)->GetId().IsAttlist()) {
2423  m_Attlist = true;
2424  if (m_TagState == eTagOutside) {
2425  m_Input.UngetChar('>');
2427  }
2428  TopFrame().SetNotag();
2429  return first;
2430  }
2431 // if spec defines no attributes, but there are some - skip them
2432  if (HasAttlist()) {
2434  }
2435  }
2436  m_Attlist = false;
2437  if ( SelfClosedTag() ) {
2438  return kInvalidMember;
2439  }
2440  if ( NextTagIsClosing() ) {
2441  if (choiceType->MayBeEmpty()) {
2442  return kInvalidMember;
2443  }
2444  TMemberIndex ind = choiceType->GetVariants().FindEmpty();
2445  if (ind != kInvalidMember) {
2446  TopFrame().SetNotag();
2447  }
2448  return ind;
2449  }
2450  if (!NextIsTag()) {
2451  const CItemsInfo& items = choiceType->GetItems();
2452  for (TMemberIndex i = items.FirstIndex(); i <= items.LastIndex(); ++i) {
2453  if (items.GetItemInfo(i)->GetId().HasNotag()) {
2455  TopFrame().SetNotag();
2456  return i;
2457  }
2458  }
2459  }
2460 
2461  }
2462  tagName = ReadName(BeginOpeningTag());
2463  } else {
2464  tagName = RejectedName();
2465  }
2466  TMemberIndex ind = choiceType->GetVariants().Find(tagName);
2467  if (ind == kInvalidMember) {
2468  ind = choiceType->GetVariants().FindDeep(tagName);
2469  if (ind != kInvalidMember) {
2470  TopFrame().SetNotag();
2471  UndoClassMember();
2472  return ind;
2473  }
2474  } else {
2475  const CVariantInfo *var_info = choiceType->GetVariantInfo(ind);
2476  if (x_IsStdXml()) {
2478  bool needUndo = false;
2479  if (GetEnforcedStdXml()) {
2480  if (type == eTypeFamilyContainer) {
2481  TTypeInfo var_type = GetRealTypeInfo(var_info->GetTypeInfo());
2482  TTypeInfo elem_type = GetContainerElementTypeInfo(var_type);
2483  needUndo = (elem_type->GetTypeFamily() == eTypeFamilyPrimitive &&
2484  elem_type->GetName() == var_type->GetName());
2485  }
2486  } else {
2487  needUndo = var_info->GetId().HasNotag() || var_info->GetId().HasAnyContent() || type == eTypeFamilyContainer;
2489  }
2490  if (needUndo) {
2491  TopFrame().SetNotag();
2492  UndoClassMember();
2493  }
2494  return ind;
2495  }
2496  }
2497  if (x_IsStdXml()) {
2498  UndoClassMember();
2499  UnexpectedMember(tagName, choiceType->GetVariants());
2500  }
2501  CTempString id = SkipStackTagName(tagName, 1, '_');
2502  ind = choiceType->GetVariants().Find(id);
2503  if ( ind == kInvalidMember ) {
2504  if (CanSkipUnknownVariants()) {
2506  UndoClassMember();
2507  } else {
2508  UnexpectedMember(tagName, choiceType->GetVariants());
2509  }
2510  }
2511  return ind;
2512 }
2513 
2515 {
2516  m_SkipNextTag = false;
2517  if (TopFrame().GetNotag()) {
2518  TopFrame().SetNotag(false);
2519  } else {
2520  CloseStackTag(0);
2521  }
2522 }
2523 
2525 {
2526  BeginData();
2527 }
2528 
2530 {
2531  char c = m_Input.GetChar();
2532  if ( c >= '0' && c <= '9' ) {
2533  return c - '0';
2534  }
2535  else if ( c >= 'A' && c <= 'Z' ) {
2536  return c - 'A' + 10;
2537  }
2538  else if ( c >= 'a' && c <= 'z' ) {
2539  return c - 'a' + 10;
2540  }
2541  else {
2542  m_Input.UngetChar(c);
2543  if ( c != '<' )
2544  ThrowError(fFormatError, "invalid char in octet string");
2545  }
2546  return -1;
2547 }
2548 
2550 {
2551  char c = SkipWS();
2552  if ( IsDigit(c) ||
2553  ( c >= 'A' && c <= 'Z' ) ||
2554  ( c >= 'a' && c <= 'z' ) ||
2555  ( c == '+' || c == '/' || c == '=')) {
2556  return c;
2557  }
2558  else {
2559  if ( c != '<' )
2560  ThrowError(fFormatError, "invalid char in base64Binary data");
2561  }
2562  return -1;
2563 }
2564 
2566  char* dst, size_t length)
2567 {
2568  size_t count = 0;
2569  if (IsCompressed()) {
2570  bool end_of_data = false;
2571  const size_t chunk_in = 80;
2572  char src_buf[chunk_in];
2573  size_t bytes_left = length;
2574  size_t src_size, src_read, dst_written;
2575  while (!end_of_data && bytes_left > chunk_in && bytes_left <= length) {
2576  for ( src_size = 0; src_size < chunk_in; ) {
2577  int c = GetBase64Char();
2578  if (c < 0) {
2579  end_of_data = true;
2580  break;
2581  }
2582  /*if (c != '=')*/ {
2583  src_buf[ src_size++ ] = (char)c;
2584  }
2585  m_Input.SkipChar();
2586  }
2587  BASE64_Decode( src_buf, src_size, &src_read,
2588  dst, bytes_left, &dst_written);
2589  if (src_size != src_read) {
2590  ThrowError(fFail, "error decoding base64Binary data");
2591  }
2592  count += dst_written;
2593  bytes_left -= dst_written;
2594  dst += dst_written;
2595  }
2596  if (end_of_data) {
2597  block.EndOfBlock();
2598  }
2599  return count;;
2600  }
2601  while ( length-- > 0 ) {
2602  int c1 = GetHexChar();
2603  if ( c1 < 0 ) {
2604  block.EndOfBlock();
2605  return count;
2606  }
2607  int c2 = GetHexChar();
2608  if ( c2 < 0 ) {
2609  *dst++ = char(c1 << 4);
2610  count++;
2611  block.EndOfBlock();
2612  return count;
2613  }
2614  else {
2615  *dst++ = char((c1 << 4) | c2);
2616  count++;
2617  }
2618  }
2619  return count;
2620 }
2621 
2623 {
2624  BeginData();
2625 }
2626 
2628  char* dst, size_t length)
2629 {
2630  size_t count = 0;
2631  while ( length-- > 0 ) {
2632  char c = m_Input.GetChar();
2633  if (c == '<') {
2634  block.EndOfBlock();
2635  break;
2636  }
2637  *dst++ = c;
2638  count++;
2639  }
2640  return count;
2641 }
2642 
2644 {
2645  ReadBool();
2646 }
2647 
2649 {
2650  ReadChar();
2651 }
2652 
2654 {
2655  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
2656  return;
2657  }
2658  BeginData();
2659  size_t i;
2660  char c = SkipWSAndComments();
2661  switch ( c ) {
2662  case '+':
2663  case '-':
2664  c = m_Input.PeekChar(1);
2665  // next char
2666  i = 2;
2667  break;
2668  default:
2669  // next char
2670  i = 1;
2671  break;
2672  }
2673  if ( c < '0' || c > '9' ) {
2674  ThrowError(fFormatError, "invalid symbol in number");
2675  }
2676  while ( (c = m_Input.PeekCharNoEOF(i)) >= '0' && c <= '9' ) {
2677  ++i;
2678  }
2679  m_Input.SkipChars(i);
2680 }
2681 
2683 {
2684  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
2685  return;
2686  }
2687  BeginData();
2688  size_t i;
2689  char c = SkipWSAndComments();
2690  switch ( c ) {
2691  case '+':
2692  c = m_Input.PeekChar(1);
2693  // next char
2694  i = 2;
2695  break;
2696  default:
2697  // next char
2698  i = 1;
2699  break;
2700  }
2701  if ( c < '0' || c > '9' ) {
2702  ThrowError(fFormatError, "invalid symbol in number");
2703  }
2704  while ( (c = m_Input.PeekCharNoEOF(i)) >= '0' && c <= '9' ) {
2705  ++i;
2706  }
2707  m_Input.SkipChars(i);
2708 }
2709 
2711 {
2712  ReadDouble();
2713 }
2714 
2716 {
2717  if (ExpectSpecialCase()!=0 && UseSpecialCaseRead()) {
2718  return;
2719  }
2720  BeginData();
2721  EEncoding enc = m_Encoding;
2722  if (type == eStringTypeUTF8) {
2724  }
2725  while ( ReadEscapedChar(m_Attlist ? '\"' : '<') >= 0 )
2726  continue;
2727  m_Encoding = enc;
2728 }
2729 
2731 {
2732  if ( !EndOpeningTagSelfClosed() )
2733  ThrowError(fFormatError, "empty tag expected");
2734 }
2735 
2737 {
2738  BeginData();
2739  for ( ;; ) {
2740  char c = m_Input.GetChar();
2741  if ( IsDigit(c) ) {
2742  continue;
2743  }
2744  else if ( c >= 'A' && c <= 'Z' ) {
2745  continue;
2746  }
2747  else if ( c >= 'a' && c <= 'z' ) {
2748  continue;
2749  }
2750  else if ( c == '\r' || c == '\n' ) {
2752  continue;
2753  }
2754  else if ( c == '+' || c == '/' || c == '=' ) {
2755  // to allow base64 byte blocks
2756  continue;
2757  }
2758  else if ( c == '<' ) {
2759  m_Input.UngetChar(c);
2760  break;
2761  }
2762  else {
2763  m_Input.UngetChar(c);
2764  ThrowError(fFormatError, "invalid char in octet string");
2765  }
2766  }
2767 }
2768 
ncbi::TMaskedQueryRegions mask
Serializable object that stores any combination of parsable data.
Definition: serialbase.hpp:264
CObjectIStreamXml –.
Definition: objistrxml.hpp:56
CObjectIStream –.
Definition: objistr.hpp:93
CObjectTypeInfo –.
Definition: objectinfo.hpp:94
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
void resize(size_type new_size)
Change size of the bvector.
Definition: bm.h:2463
size_type size() const noexcept
Returns bvector's capacity (number of bits it can store)
Definition: bm.h:1300
bool set_bit(size_type n, bool val=true)
Sets bit n.
Definition: bm.h:4227
bvector_size_type size_type
Definition: bm.h:121
void clear(const size_type *ids, size_type ids_size, bm::sort_order so=bm::BM_UNKNOWN)
clear list of bits in this bitset
Definition: bm.h:4149
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: set.hpp:45
Include a standard set of the NCBI C++ Toolkit most basic headers.
static unsigned char depth[2 *(256+1+29)+1]
static const unsigned long CR
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
static DLIST_TYPE *DLIST_NAME() last(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:51
static int type
Definition: getdata.c:31
static const char * str(char *buf, int n)
Definition: stats.c:84
static char tmp[3200]
Definition: utf8.c:42
int offset
Definition: replacements.h:160
char data[12]
Definition: iconv.c:80
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
const CMemberId & GetId(void) const
bool HasAnyContent(void) const
bool IsAttlist(void) const
const string & GetName(void) const
TMemberIndex Find(const CTempString &name) const
Definition: memberlist.cpp:256
TMemberIndex FindEmpty(void) const
Definition: memberlist.cpp:403
TMemberIndex FindDeep(const CTempString &name, bool search_attlist=false, const CClassTypeInfoBase **classInfo=nullptr) const
Definition: memberlist.cpp:265
const CItemInfo * GetItemInfo(TMemberIndex index) const
static TMemberIndex FirstIndex(void)
Definition: memberlist.hpp:78
bool HasNotag(void) const
TEnumValueType FindValue(const CTempString &name) const
Find numeric value by the name of the enum.
Definition: enumerated.cpp:124
const string & GetName(void) const
Definition: enumerated.cpp:79
bool HaveNoPrefix(void) const
TTypeInfo GetTypeInfo(void) const
TMemberIndex LastIndex(void) const
Definition: memberlist.hpp:82
bool IsInteger(void) const
Check whether the type is defined as INTEGER in ASN.1 spec.
Definition: enumvalues.hpp:75
string ToString(void) const
Definition: memberid.cpp:113
static TObjectType & Get(TObjectPtr object)
Definition: serialutil.hpp:56
void * TObjectPtr
Definition: serialdef.hpp:55
int TEnumValueType
Definition: serialdef.hpp:232
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const TMemberIndex kInvalidMember
Special value returned from FindMember.
Definition: serialdef.hpp:237
void SetName(const string &name)
Set local name.
void AddAttribute(const string &name, const string &ns_name, const CStringUTF8 &value)
Add attribute.
void SetNamespacePrefix(const string &ns_prefix)
Set namespace prefix.
ETypeFamily
Type family.
Definition: serialdef.hpp:138
EStringType
String type.
Definition: serialdef.hpp:185
void SetNamespaceName(const string &ns_name)
Set namespace name.
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
void SetValue(const CStringUTF8 &value)
Set normalized value.
@ ePrimitiveValueAny
Definition: serialdef.hpp:160
@ eTypeFamilyContainer
Definition: serialdef.hpp:142
@ eTypeFamilyPointer
Definition: serialdef.hpp:143
@ eTypeFamilyPrimitive
Definition: serialdef.hpp:139
@ eStringTypeUTF8
UTF8-encoded string.
Definition: serialdef.hpp:187
@ eSerial_Xml
XML.
Definition: serialdef.hpp:75
CIStreamBuffer m_Input
Definition: objistr.hpp:1048
virtual void SkipBitString(void) override
char BeginClosingTag(void)
Definition: objistrxml.cpp:420
void ReadWord(string &s, EStringType type=eStringTypeVisible)
static ETypeFamily GetRealTypeFamily(TTypeInfo typeInfo)
Definition: objstack.cpp:343
TFlags SetFlags(TFlags flags)
char ReplaceVisibleChar(char c, EFixNonPrint fix_method, const CObjectStack *io, const CTempString &str, char subst)
Definition: objistr.cpp:1855
virtual void SkipByteBlock(void) override
void EndTag(void)
Definition: objistrxml.cpp:308
CTempString SkipStackTagName(CTempString tag, size_t level)
void OpenTag(const string &e)
virtual void StartDelayBuffer(void) override
virtual TMemberIndex BeginClassMember(const CClassTypeInfo *classType) override
bool SelfClosedTag(void) const
TMemberIndex HasAnyContent(const CClassTypeInfoBase *classType, TMemberIndex pos=kInvalidMember)
virtual void ReadBitString(CBitString &obj) override
virtual void SkipUNumber(void) override
virtual char * ReadCString(void) override
virtual Uint4 ReadUint4(void) override
static CObjectIStream * CreateObjectIStreamXml(void)
Definition: objistrxml.cpp:52
virtual CRef< CByteSource > EndDelayBuffer(void) override
void CheckStdXml(TTypeInfo classType)
TUnicodeSymbol ReadUtf8Char(char ch)
Definition: objistrxml.cpp:876
CObjectTypeInfo GetPointedType(void) const
Get type information of data to which this type refers.
Definition: objectinfo.cpp:91
bool InsideOpeningTag(void) const
virtual void EndChoiceVariant(void) override
virtual void SkipChar(void) override
virtual string PeekNextTypeName(void) override
Peek next data type name in XML stream.
Definition: objistrxml.cpp:677
void OpenTagIfNamed(TTypeInfo type)
static TTypeInfo GetRealTypeInfo(TTypeInfo typeInfo)
Definition: objstack.cpp:331
bool ReadAnyContent(const string &ns_prefix, string &value)
bool GetEnforcedStdXml(void)
Get scope prefixes handling parameter.
Definition: objistrxml.hpp:117
#define BEGIN_OBJECT_FRAME(Type)
Definition: objstack.hpp:224
#define ThrowError(flag, mess)
Definition: objstack.hpp:113
~CObjectIStreamXml(void)
Definition: objistrxml.cpp:80
virtual void ReadAnyContentObject(CAnyContentObject &obj) override
bool HasTypeInfo(void) const
void EndClosingTag(void)
virtual void SkipFNumber(void) override
EEncoding GetEncoding(void) const
Get XML character encoding.
Definition: objistrxml.cpp:103
virtual TMemberIndex BeginChoiceVariant(const CChoiceTypeInfo *choiceType) override
virtual char ReadChar(void) override
Definition: objistrxml.cpp:984
void EndArrayElement(void)
virtual string ReadFileHeader(void) override
Read file header.
Definition: objistrxml.cpp:587
virtual bool EndOfData(void)
Check if there is still some meaningful data that can be read; in text streams this function will ski...
Definition: objistr.cpp:588
virtual size_t ReadBytes(ByteBlock &block, char *dst, size_t length) override
bool IsCompressed(void) const
Definition: objstack.cpp:193
void SetSpecialCaseUsed(ESpecialCaseRead used)
Definition: objistr.hpp:1136
#define BEGIN_OBJECT_FRAME2(Type, Arg)
Definition: objstack.hpp:225
MLIOVIR void ReadContainer(const CContainerTypeInfo *containerType, TObjectPtr containerPtr)
Definition: objistr.cpp:1318
char SkipWSAndComments(void)
Definition: objistrxml.cpp:243
EEncoding m_StringEncoding
Definition: objistrxml.hpp:303
char SkipWS(void)
Definition: objistrxml.cpp:223
void SkipContainerContents(const CContainerTypeInfo *containerType)
void SkipObject(const CObjectTypeInfo &objectType)
Skip child object.
Definition: objistr.cpp:1102
CStringUTF8 m_Utf8Buf
Definition: objistrxml.hpp:307
virtual double ReadDouble(void) override
void OpenStackTag(size_t level)
virtual void ResetState(void) override
Definition: objistrxml.cpp:84
map< string, string > m_NsNameToPrefix
Definition: objistrxml.hpp:306
void BeginArrayElement(TTypeInfo elementType)
virtual void EndNamedType(void) override
char BeginOpeningTag(void)
Definition: objistrxml.cpp:405
void Found_slash_gt(void)
virtual void BeginContainer(const CContainerTypeInfo *containerType) override
void UnexpectedMember(const CTempString &id, const CItemsInfo &items)
virtual Int8 ReadInt8(void) override
CObjectInfo ReadObject(void)
Definition: objistr.cpp:1075
virtual void ResetState(void) override
Definition: objistr.cpp:486
CTempString ReadName(char c)
Definition: objistrxml.cpp:432
void CloseTagIfNamed(TTypeInfo type)
void SetNotag(bool set=true)
bool CanSkipUnknownMembers(void)
Simple check if it's allowed to skip unknown members.
bool InsideTag(void) const
void EndSelfClosedTag(void)
void Found_lt_slash(void)
void CloseStackTag(size_t level)
void SkipAttributeValue(char c)
Definition: objistrxml.cpp:537
virtual void BeginBytes(ByteBlock &) override
TFrame & FetchFrameFromTop(size_t index)
virtual size_t ReadChars(CharBlock &block, char *dst, size_t length) override
virtual void BeginChoice(const CChoiceTypeInfo *choiceType) override
void ReadAttributeValue(string &value, bool skipClosing=false)
Definition: objistrxml.cpp:896
bool UseSpecialCaseRead(void)
Definition: objistrxml.cpp:380
int ReadEncodedChar(char endingChar, EStringType type, bool &encoded)
Definition: objistrxml.cpp:824
bool ReadCDSection(string &s)
virtual void BeginClass(const CClassTypeInfo *classInfo) override
bool NextTagIsClosing(void)
CTempString SkipTagName(CTempString tag, const char *s, size_t length)
virtual bool EndOfData(void) override
Check if there is still some meaningful data that can be read; this function will skip white spaces a...
Definition: objistrxml.cpp:118
char ReadUndefinedAttributes(void)
Definition: objistrxml.cpp:919
virtual void ReadString(string &s, EStringType type=eStringTypeVisible) override
void Found_gt(void)
TObjectIndex ReadObjectPointer(void) override
virtual void SkipSNumber(void) override
virtual void BeginNamedType(TTypeInfo namedTypeInfo) override
static TTypeInfo GetContainerElementTypeInfo(TTypeInfo typeInfo)
Definition: objstack.cpp:348
void SetDefaultStringEncoding(EEncoding enc)
Set default encoding of 'string' objects If XML data encoding is different, string will be converted ...
Definition: objistrxml.cpp:108
virtual void BeginChars(CharBlock &) override
#define END_OBJECT_FRAME()
Definition: objstack.hpp:227
size_t GetStackDepth(void) const
virtual void SkipAnyContentObject(void) override
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
virtual void ReadNull(void) override
TEnumValueType ReadEnum(const CEnumeratedTypeValues &values) override
bool IsKnownElement(const CTempString &name) const
Definition: objstack.cpp:308
const TFrame & TopFrame(void) const
TTypeInfo GetTypeInfo(void) const
ETagState m_TagState
Definition: objistrxml.hpp:293
bool SkipAnyContent(void)
EFixNonPrint x_FixCharsMethod(void) const
Definition: objistr.cpp:311
EEncoding m_Encoding
Definition: objistrxml.hpp:302
TFailFlags SetFailFlags(TFailFlags flags, const char *message=0)
Set fail flags.
Definition: objistr.cpp:552
TFlags ClearFlags(TFlags flags)
virtual void SkipBool(void) override
bool StackIsEmpty(void) const
TMemberIndex FindDeep(TTypeInfo type, const CTempString &name) const
virtual bool BeginContainerElement(TTypeInfo elementType) override
bool OutsideTag(void) const
virtual void EndContainer(void) override
const CMemberId & GetMemberId(void) const
int x_VerifyChar(int)
Definition: objistrxml.cpp:819
virtual bool ReadBool(void) override
Definition: objistrxml.cpp:938
EPointerType ReadPointerType(void) override
ETypeFamily GetTypeFamily(void) const
Get data type family.
void BeginData(void)
void SkipQDecl(void)
Definition: objistrxml.cpp:545
virtual Int4 ReadInt4(void) override
Definition: objistrxml.cpp:996
void Found_lt(void)
MLIOVIR void ReadNamedType(TTypeInfo namedTypeInfo, TTypeInfo typeInfo, TObjectPtr object)
Definition: objistr.cpp:1284
bool HasMoreElements(TTypeInfo elementType)
TConstObjectPtr GetMemberDefault(void) const
Definition: objistr.hpp:1132
size_t TObjectIndex
Definition: objistr.hpp:1029
CStringUTF8::const_iterator m_Utf8Pos
Definition: objistrxml.hpp:308
bool WillHaveName(TTypeInfo elementType)
MLIOVIR void SkipContainer(const CContainerTypeInfo *containerType)
Definition: objistr.cpp:1349
int ExpectSpecialCase(void) const
Definition: objistr.hpp:1128
void FindFileHeader(bool find_XMLDecl=true)
Definition: objistrxml.cpp:687
void SetEnforcedStdXml(bool set=true)
Set up scope prefixes handling.
Definition: objistrxml.cpp:137
virtual void EndClassMember(void) override
string ReadOtherPointer(void) override
virtual void UndoClassMember(void) override
bool HasAttlist(void)
virtual void SkipString(EStringType type=eStringTypeVisible) override
virtual void EndClass(void) override
bool ThisTagIsSelfClosed(void)
bool NextIsTag(void)
EFrameType GetFrameType(void) const
bool CanSkipUnknownVariants(void)
Simple check if it's allowed to skip unknown variants.
virtual void Location(string &, size_t &) const override
Get current stream location as tuple (positiontype:string, size_t).
Definition: objistrxml.cpp:131
EEncoding GetDefaultStringEncoding(void) const
Get default encoding of 'string' objects.
Definition: objistrxml.cpp:113
int x_ReadEncodedChar(char endingChar, EStringType type, bool &encoded)
Definition: objistrxml.cpp:829
map< string, string > m_NsPrefixToName
Definition: objistrxml.hpp:305
CTempString RejectedName(void)
Definition: objistrxml.cpp:525
virtual void StartDelayBuffer(void)
Definition: objistr.cpp:1014
bool x_IsStdXml(void)
Definition: objistrxml.hpp:279
Type x_UseMemberDefault(void)
Definition: objistrxml.cpp:151
char x_FixCharsSubst(void) const
Definition: objistr.hpp:1044
int ReadEscapedChar(char endingChar, bool *encoded=0)
Definition: objistrxml.cpp:727
virtual void EndChoice(void) override
CTempString ReadAttributeName(void)
Definition: objistrxml.cpp:889
EPrimitiveValueType GetPrimitiveValueType(void) const
Get type of primitive value.
Definition: objectinfo.cpp:109
void x_EndTypeNamespace(void)
Definition: objistrxml.cpp:707
void ReadTagData(string &s, EStringType type=eStringTypeVisible)
virtual void EndContainerElement(void) override
bool EndOpeningTagSelfClosed(void)
Definition: objistrxml.cpp:342
void CloseTag(const string &e)
CObjectTypeInfo GetElementType(void) const
Get type information of an element of container.
Definition: objectinfo.cpp:85
virtual CRef< CByteSource > EndDelayBuffer(void)
Definition: objistr.cpp:1019
void ReadCompressedBitString(CBitString &data)
Definition: objistr.cpp:1842
int GetHexChar(void)
virtual void SkipNull(void) override
virtual Uint8 ReadUint8(void) override
int GetBase64Char(void)
void ReadContainerContents(const CContainerTypeInfo *containerType, TObjectPtr containerPtr)
@ fIllegalCall
Illegal in a given context function call.
Definition: objistr.hpp:383
@ fNotImplemented
Method is not implemented.
Definition: objistr.hpp:389
@ fMissingValue
Mandatory value was missing in the input.
Definition: objistr.hpp:394
@ fInvalidData
Input data is incorrect (e.g. invalid enum)
Definition: objistr.hpp:381
@ fFail
Internal error, the real reason is unclear.
Definition: objistr.hpp:385
@ fUnknownValue
Unknown value was present in the input.
Definition: objistr.hpp:399
@ fFormatError
Input file formatting does not conform with specification.
Definition: objistr.hpp:377
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
std::string CStringUTF8
Definition: ncbistl.hpp:254
Uint4 GetUint4(void)
Definition: strbuffer.cpp:671
char PeekChar(size_t offset=0)
Int8 GetInt8(void)
Definition: strbuffer.cpp:702
Int8 GetStreamPosAsInt8(void) const
Uint8 GetUint8(void)
Definition: strbuffer.cpp:748
char SkipSpaces(void)
Definition: strbuffer.cpp:213
Int4 GetInt4(void)
Definition: strbuffer.cpp:625
void UngetChar(char c)
size_t PeekFindChar(char c, size_t limit)
Definition: strbuffer.cpp:292
virtual void AddChunk(const char *buffer, size_t bufferLength)
Add data to the sub-source.
Definition: bytesrc.cpp:125
void SkipEndOfLine(char lastChar)
Definition: strbuffer.cpp:525
void SkipChar(void)
char GetChar(void)
size_t GetLine(void) const
void SkipChars(size_t count)
const char * GetCurrentPos(void) const
void FindChar(char c)
Definition: strbuffer.cpp:257
char PeekCharNoEOF(size_t offset=0)
CRef< CSubSourceCollector > & GetSubSourceCollector(void)
Definition: strbuffer.hpp:162
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2821
EEncoding
Definition: ncbistr.hpp:199
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static string AsSingleByteString(const CTempString &src, EEncoding encoding, const char *substitute_on_error=0, EValidate validate=eNoValidate)
Convert UTF8 string into a single-byte character representation.
Definition: ncbistr.cpp:6983
static int strcmp(const char *s1, const char *s2)
String compare.
Definition: ncbistr.hpp:5208
Uint4 TUnicodeSymbol
Unicode character.
Definition: ncbistr.hpp:141
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3201
static double StringToDoublePosix(const char *str, char **endptr=0, TStringToNumFlags flags=0)
Convert string to double-precision value (analog of strtod function)
Definition: ncbistr.cpp:984
static TUnicodeSymbol DecodeFirst(char ch, SIZE_TYPE &more)
Begin converting first character of UTF8 sequence into Unicode.
Definition: ncbistr.cpp:7154
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
static char SymbolToChar(TUnicodeSymbol sym, EEncoding encoding)
Convert Unicode code point into encoded character.
Definition: ncbistr.cpp:6864
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3889
#define NcbiEmptyString
Definition: ncbistr.hpp:122
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
Definition: ncbistr.hpp:5109
static TUnicodeSymbol DecodeNext(TUnicodeSymbol chU, char ch)
Convert next character of UTF8 sequence into Unicode.
Definition: ncbistr.cpp:7177
static TUnicodeSymbol CharToSymbol(char ch, EEncoding encoding)
Convert encoded character into Unicode.
Definition: ncbistr.cpp:6839
@ eEncoding_Windows_1252
Definition: ncbistr.hpp:207
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
Definition: ncbistr.hpp:203
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
@ eEncoding_Unknown
Definition: ncbistr.hpp:200
@ fDecimalPosixFinite
StringToDouble*(): Keep result finite and normalized: if DBL_MAX < result < INF, result becomes DBL_M...
Definition: ncbistr.hpp:302
const string & GetName(void) const
Get name of this type.
Definition: typeinfo.cpp:249
const CItemsInfo & GetItems(void) const
EDataSpec GetDataSpec(void) const
Definition: typeinfo.hpp:278
ETypeFamily GetTypeFamily(void) const
TObjectPtr AddElement(TObjectPtr containerPtr, TConstObjectPtr elementPtr, ESerialRecursionMode how=eRecursive) const
TTypeInfo GetPointedType(void) const
const CItemsInfo & GetVariants(void) const
bool MayBeEmpty(void) const
Definition: choice.hpp:129
const CMemberInfo * GetMemberInfo(TMemberIndex index) const
const CVariantInfo * GetVariantInfo(TMemberIndex index) const
bool Implicit(void) const
void ReadData(CObjectIStream &in, TObjectPtr object) const
size_t GetCodeVersion(void) const
Definition: typeinfo.hpp:274
TConstObjectPtr GetElementPtr(const CConstIterator &it) const
bool InitIterator(CConstIterator &it, TConstObjectPtr containerPtr) const
bool NextElement(CConstIterator &it) const
void EraseAllElements(CIterator &it) const
const CItemsInfo & GetMembers(void) const
bool IsFullAlias(void) const
Definition: aliasinfo.hpp:79
TTypeInfo GetElementType(void) const
bool IsImplicitNonEmpty(void) const
Definition: classinfo.cpp:112
enum ENcbiOwnership EOwnership
Ownership relations between objects.
int i
int len
constexpr bool empty(list< Ts... >) noexcept
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const char * tag
std::istream & in(std::istream &in_, double &x_)
bool BAD_CHAR(int x)
Definition: objistrxml.cpp:816
static bool IsWhiteSpace(char c)
Definition: objistrxml.cpp:212
static bool IsNameChar(char c)
Definition: objistrxml.cpp:204
static bool IsIdeographic(char)
Definition: objistrxml.cpp:174
static bool IsCombiningChar(char)
Definition: objistrxml.cpp:192
static const char * s_SchemaInstanceNamespace
Definition: objistrxml.cpp:50
static bool IsFirstNameChar(char c)
Definition: objistrxml.cpp:186
static bool IsExtender(char c)
Definition: objistrxml.cpp:198
static bool IsBaseChar(char c)
Definition: objistrxml.cpp:157
static bool IsLetter(char c)
Definition: objistrxml.cpp:180
static bool IsEndOfTagChar(char c)
Definition: objistrxml.cpp:218
static bool IsDigit(char c)
Definition: objistrxml.cpp:168
#define BASE64_Decode
Definition: ncbi_base64.h:42
#define NcbiSysChar_strdup
Definition: ncbisys.hpp:178
Definition: type.c:6
#define _ASSERT
#define Type
else result
Definition: token2.c:20
Modified on Wed May 29 18:34:15 2024 by modify_doxy.py rev. 669887