stringio.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * File: stringio.h $XConsortium: stringio.h /main/3 1995/10/26 16:10:00 rswiston $
  25. *
  26. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  27. * (c) Copyright 1993, 1994 International Business Machines Corp.
  28. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  29. * (c) Copyright 1993, 1994 Novell, Inc.
  30. */
  31. #include <codelibs/boolean.h>
  32. #define __PRIVATE_
  33. #include <codelibs/privbuf.h>
  34. class _StringIO
  35. {
  36. privbuf_strvec ptr;
  37. int curr;
  38. int old_curr;
  39. char const *old_ccp;
  40. int doit(int commit);
  41. public:
  42. void push(char const *ccp);
  43. _StringIO();
  44. _StringIO(char const *ccp);
  45. void unget();
  46. int get();
  47. int next();
  48. boolean in_expansion();
  49. };
  50. inline
  51. _StringIO::_StringIO()
  52. {
  53. curr = old_curr = -1;
  54. old_ccp = 0;
  55. }
  56. inline void
  57. _StringIO::push(char const *ccp)
  58. {
  59. ptr[++curr] = (char*)ccp;
  60. }
  61. inline
  62. _StringIO::_StringIO(char const *ccp)
  63. {
  64. curr = old_curr = -1;
  65. old_ccp = 0;
  66. push(ccp);
  67. }
  68. inline void
  69. _StringIO::unget()
  70. {
  71. if (curr >= 0)
  72. ptr[curr] = (char*)old_ccp;
  73. curr = old_curr;
  74. }
  75. inline int
  76. _StringIO::get()
  77. {
  78. return doit(1);
  79. }
  80. inline int
  81. _StringIO::next()
  82. {
  83. return doit(0);
  84. }
  85. inline boolean
  86. _StringIO::in_expansion()
  87. {
  88. return ((boolean)(curr > 0));
  89. }