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

Go to the SVN repository for this file.

1 /* $Id: srcutil.cpp 74404 2016-08-31 12:38:54Z ivanov $
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/ncbistre.hpp>
36 #include "srcutil.hpp"
37 
39 
40 string Identifier(const string& typeName, bool capitalize)
41 {
42  string s;
43  s.reserve(typeName.size());
44  string::const_iterator i = typeName.begin();
45  if ( i != typeName.end() ) {
46  if (isalnum((unsigned char)(*i))) {
47  s += capitalize? (char)toupper((unsigned char)(*i)) : *i;
48  } else {
49  string ent(NStr::HtmlEntity((unsigned char)(*i)));
50  if (*i != '_' && !ent.empty()) {
51  s += ent;
52  } else {
53  s += '_';
54  }
55  }
56  while ( ++i != typeName.end() ) {
57  char c = *i;
58  if ( c == ':' ) {
59  continue;
60  }
61  if ( c == '-' || c == '.' || c == '_') {
62  c = '_';
63  } else if (!isalnum((unsigned char)c)) {
64  string ent(NStr::HtmlEntity((unsigned char)(*i)));
65  if (!ent.empty()) {
66  s += ent;
67  continue;
68  }
69  c = '_';
70  }
71  s += c;
72  }
73  }
74  return s;
75 }
76 
77 string Tabbed(const string& code, const char* tab)
78 {
79  string out;
80  SIZE_TYPE size = code.size();
81  if ( size != 0 ) {
82  if ( !tab )
83  tab = " ";
84  const char* ptr = code.data();
85  while ( size > 0 ) {
86  out += tab;
87  const char* endl =
88  reinterpret_cast<const char*>(memchr(ptr, '\n', size));
89  if ( !endl ) { // no more '\n'
90  out.append(ptr, ptr + size);
91  out += '\n';
92  break;
93  }
94  ++endl; // skip '\n'
95  size_t lineSize = endl - ptr;
96  out.append(ptr, ptr + lineSize);
97  ptr = endl;
98  size -= lineSize;
99  }
100  }
101  return out;
102 }
103 
105  const char* tab)
106 {
107  size_t size = code.size();
108  if ( size != 0 ) {
109  if ( !tab )
110  tab = " ";
111  const char* ptr = code.data();
112  while ( size > 0 ) {
113  out << tab;
114  const char* endl =
115  reinterpret_cast<const char*>(memchr(ptr, '\n', size));
116  if ( !endl ) { // no more '\n'
117  out.write(ptr, size) << '\n';
118  break;
119  }
120  ++endl; // skip '\n'
121  size_t lineSize = endl - ptr;
122  out.write(ptr, lineSize);
123  ptr = endl;
124  size -= lineSize;
125  }
126  }
127  return out;
128 }
129 
131 {
132  return out << '\n' << string(2*indent,' ');
133 }
134 
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static string HtmlEntity(TUnicodeSymbol uch)
Returns HTML entity name for this symbol if one exists (without leading ampersand and trailing semico...
Definition: ncbistr.cpp:4512
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
int isalnum(Uchar c)
Definition: ncbictype.hpp:62
int toupper(Uchar c)
Definition: ncbictype.hpp:73
NCBI C++ stream class wrappers for triggering between "new" and "old" C++ stream libraries.
string indent(" ")
string Tabbed(const string &code, const char *tab)
Definition: srcutil.cpp:77
CNcbiOstream & WriteTabbed(CNcbiOstream &out, const string &code, const char *tab)
Definition: srcutil.cpp:104
string Identifier(const string &typeName, bool capitalize)
Definition: srcutil.cpp:40
CNcbiOstream & PrintASNNewLine(CNcbiOstream &out, int indent)
Definition: srcutil.cpp:130
Definition: inftrees.h:24
Modified on Sat Dec 02 09:22:21 2023 by modify_doxy.py rev. 669887