Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
2.8 KiB

  1. /***
  2. *streamb1.cpp - non-core functions for streambuf class.
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * None-core functions for streambuf class.
  8. *
  9. *Revision History:
  10. * 11-18-91 KRS Split off from streamb.cxx.
  11. * 06-14-95 CFW Comment cleanup.
  12. *
  13. *******************************************************************************/
  14. #include <cruntime.h>
  15. #include <internal.h>
  16. #include <iostream.h>
  17. #pragma hdrstop
  18. /***
  19. *int streambuf::snextc() -
  20. *
  21. *Purpose:
  22. * Increments get_pointer and returns the character following the new
  23. * get_pointer.
  24. *
  25. *Entry:
  26. * None.
  27. *
  28. *Exit:
  29. * Returns the next character or EOF.
  30. *
  31. *Exceptions:
  32. * Returns EOF if error.
  33. *
  34. *******************************************************************************/
  35. int streambuf::snextc()
  36. {
  37. if (_fUnbuf)
  38. {
  39. if (x_lastc==EOF)
  40. underflow(); // skip 1st character
  41. return x_lastc = underflow(); // return next character, or EOF
  42. }
  43. else
  44. {
  45. if ((!egptr()) || (gptr()>=egptr()))
  46. underflow(); // make sure buffer
  47. if ((++_gptr) < egptr())
  48. return (int)(unsigned char) *gptr();
  49. return underflow(); // returns next character, or EOF
  50. }
  51. }
  52. /***
  53. *int streambuf::sbumpc() -
  54. *
  55. *Purpose:
  56. * Increments get_pointer and returns the character that the previous
  57. * get_pointer pointed to.
  58. *
  59. *Entry:
  60. * None.
  61. *
  62. *Exit:
  63. * Returns current character before bumping get pointer.
  64. *
  65. *Exceptions:
  66. * Returns EOF if error.
  67. *
  68. *******************************************************************************/
  69. int streambuf::sbumpc()
  70. {
  71. int c;
  72. if (_fUnbuf) // no buffer
  73. {
  74. if (x_lastc==EOF)
  75. {
  76. c = underflow();
  77. }
  78. else
  79. {
  80. c = x_lastc;
  81. x_lastc = EOF;
  82. }
  83. }
  84. else
  85. {
  86. if( gptr() < egptr() )
  87. {
  88. c = (int)(unsigned char)*(gptr());
  89. }
  90. else
  91. {
  92. c = underflow();
  93. }
  94. _gptr++;
  95. }
  96. return c;
  97. }
  98. /***
  99. *void streambuf::stossc() - advance get pointer
  100. *
  101. *Purpose:
  102. * Advances the get pointer. Does not check for EOF.
  103. *
  104. *Entry:
  105. * None.
  106. *
  107. *Exit:
  108. * None.
  109. *
  110. *Exceptions:
  111. *
  112. *******************************************************************************/
  113. void streambuf::stossc()
  114. {
  115. if (_fUnbuf)
  116. {
  117. if (x_lastc==EOF)
  118. underflow(); // throw away current character
  119. else
  120. x_lastc=EOF; // discard current cached character
  121. }
  122. else
  123. {
  124. if (gptr() >= egptr())
  125. underflow();
  126. if (gptr() < egptr())
  127. _gptr++;
  128. }
  129. }
  130. /***
  131. *int streambuf::sgetc() -
  132. *
  133. *Purpose:
  134. * Returns the character that the previous get_pointer points to.
  135. * DOES NOT advance the get pointer.
  136. *
  137. *Entry:
  138. * None.
  139. *
  140. *Exit:
  141. * Returns current character or EOF if error.
  142. *
  143. *Exceptions:
  144. * Returns EOF if error.
  145. *
  146. *******************************************************************************/
  147. int streambuf::sgetc()
  148. {
  149. if (_fUnbuf) // no buffer
  150. {
  151. if (x_lastc==EOF)
  152. x_lastc = underflow();
  153. return x_lastc;
  154. }
  155. else
  156. return underflow();
  157. }