srcutil.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:4k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: srcutil.cpp,v $
  4.  * PRODUCTION Revision 1000.1  2004/06/01 19:43:42  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /*  $Id: srcutil.cpp,v 1000.1 2004/06/01 19:43:42 gouriano Exp $
  10. * ===========================================================================
  11. *
  12. *                            PUBLIC DOMAIN NOTICE
  13. *               National Center for Biotechnology Information
  14. *
  15. *  This software/database is a "United States Government Work" under the
  16. *  terms of the United States Copyright Act.  It was written as part of
  17. *  the author's official duties as a United States Government employee and
  18. *  thus cannot be copyrighted.  This software/database is freely available
  19. *  to the public for use. The National Library of Medicine and the U.S.
  20. *  Government have not placed any restriction on its use or reproduction.
  21. *
  22. *  Although all reasonable efforts have been taken to ensure the accuracy
  23. *  and reliability of the software and data, the NLM and the U.S.
  24. *  Government do not and cannot warrant the performance or results that
  25. *  may be obtained by using this software or data. The NLM and the U.S.
  26. *  Government disclaim all warranties, express or implied, including
  27. *  warranties of performance, merchantability or fitness for any particular
  28. *  purpose.
  29. *
  30. *  Please cite the author in any work or product based on this material.
  31. *
  32. * ===========================================================================
  33. *
  34. * Author: Eugene Vasilchenko
  35. *
  36. * File Description:
  37. *   !!! PUT YOUR DESCRIPTION HERE !!!
  38. *
  39. * ---------------------------------------------------------------------------
  40. * $Log: srcutil.cpp,v $
  41. * Revision 1000.1  2004/06/01 19:43:42  gouriano
  42. * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
  43. *
  44. * Revision 1.3  2004/05/17 21:03:14  gorelenk
  45. * Added include of PCH ncbi_pch.hpp
  46. *
  47. * Revision 1.2  2001/05/17 15:07:12  lavr
  48. * Typos corrected
  49. *
  50. * Revision 1.1  2000/11/29 17:42:45  vasilche
  51. * Added CComment class for storing/printing ASN.1/XML module comments.
  52. * Added srcutil.hpp file to reduce file dependency.
  53. *
  54. * ===========================================================================
  55. */
  56. #include <ncbi_pch.hpp>
  57. #include <corelib/ncbistd.hpp>
  58. #include <corelib/ncbistre.hpp>
  59. #include <serial/datatool/srcutil.hpp>
  60. BEGIN_NCBI_SCOPE
  61. string Identifier(const string& typeName, bool capitalize)
  62. {
  63.     string s;
  64.     s.reserve(typeName.size());
  65.     string::const_iterator i = typeName.begin();
  66.     if ( i != typeName.end() ) {
  67.         s += capitalize? toupper(*i): *i;
  68.         while ( ++i != typeName.end() ) {
  69.             char c = *i;
  70.             if ( c == '-' || c == '.' )
  71.                 c = '_';
  72.             s += c;
  73.         }
  74.     }
  75.     return s;
  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. CNcbiOstream& WriteTabbed(CNcbiOstream& out, const string& code,
  104.                           const char* tab)
  105. {
  106.     size_t size = code.size();
  107.     if ( size != 0 ) {
  108.         if ( !tab )
  109.             tab = "    ";
  110.         const char* ptr = code.data();
  111.         while ( size > 0 ) {
  112.             out << tab;
  113.             const char* endl =
  114.                 reinterpret_cast<const char*>(memchr(ptr, 'n', size));
  115.             if ( !endl ) { // no more 'n'
  116.                 out.write(ptr, size) << 'n';
  117.                 break;
  118.             }
  119.             ++endl; // skip 'n'
  120.             size_t lineSize = endl - ptr;
  121.             out.write(ptr, lineSize);
  122.             ptr = endl;
  123.             size -= lineSize;
  124.         }
  125.     }
  126.     return out;
  127. }
  128. CNcbiOstream& PrintASNNewLine(CNcbiOstream& out, int indent)
  129. {
  130.     out <<
  131.         'n';
  132.     for ( int i = 0; i < indent; ++i )
  133.         out << "  ";
  134.     return out;
  135. }
  136. END_NCBI_SCOPE