home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / COMMAND / inputstring.cpp < prev    next >
C/C++ Source or Header  |  1998-04-20  |  2KB  |  115 lines

  1. // inputstring.cpp
  2.  
  3. // Copyright (C) 1997  Cliff Johnson                                       //
  4. //                                                                         //
  5. // This program is free software; you can redistribute it and/or           //
  6. // modify it under the terms of the GNU  General Public                    //
  7. // License as published by the Free Software Foundation; either            //
  8. // version 2 of the License, or (at your option) any later version.        //
  9. //                                                                         //
  10. // This software is distributed in the hope that it will be useful,        //
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of          //
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
  13. // General Public License for more details.                                //
  14. //                                                                         //
  15. // You should have received a copy of the GNU General Public License       //
  16. // along with this software (see COPYING.LIB); if not, write to the        //
  17. // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
  18.  
  19. #include "inputstring.h"
  20.  
  21. extern "C"
  22. {
  23. #include <string.h>
  24. }
  25.  
  26. #include <strstream.h>
  27.  
  28.  
  29. InputString::InputString()
  30. {
  31.     c_string[0]='\0';
  32.     cnt=0;
  33. }
  34.  
  35. InputString::InputString(char* s)
  36. {
  37.     strncpy(c_string,s,255);
  38.     cnt=strlen(s);
  39.     if (cnt > 255){
  40.         c_string[255]='\0';
  41.         cnt=255;
  42.     }
  43. }
  44.  
  45. void InputString::Clear()
  46. {
  47.     for(int i=0;i<256;i++)c_string[i]='\0';
  48.     cnt=0;
  49. }
  50.  
  51. void InputString::AddChar(char c)
  52. {
  53.     c_string[cnt]=c;
  54.     cnt++;
  55. }
  56.  
  57. void InputString::AppendString(const int& ix)
  58. {
  59.     char * p;
  60.     int pcnt;
  61.     ostrstream data;
  62.     data << ix;
  63.     p = data.str();
  64.     pcnt = data.pcount();
  65.     for(int i=0; i< pcnt && cnt < 255 ; i++){
  66.         c_string[cnt] = p[i];
  67.         cnt++;
  68.     }
  69. }
  70.  
  71. void InputString::AppendString(const char* sx)
  72. {
  73.     int ix = strlen(sx);
  74.     for(int i = 0;(i < ix) &&( cnt < 255); i++)
  75.     {
  76.         c_string[cnt]=sx[i];
  77.         cnt++;
  78.     }
  79. }
  80.  
  81.  
  82. void InputString::DelChar()
  83. {
  84.   if(cnt>0){
  85.     cnt--;
  86.     c_string[cnt]='\0';
  87.   }
  88. }
  89.  
  90. const char* InputString::GetString() const
  91. {
  92.     return c_string;
  93. }
  94.  
  95. bool InputString::IsClear() const
  96. {
  97.     return (cnt==0);
  98. }
  99.     
  100. int InputString::InputSize() const
  101. {
  102.     return cnt;
  103. }
  104.  
  105. void InputString::ClearAndLoad(char* s)
  106. {
  107.     Clear();
  108.     strncpy(c_string,s,255);
  109.     cnt=strlen(s);
  110.     if (cnt > 255){
  111.         c_string[255]='\0';
  112.         cnt=255;
  113.     }
  114. }
  115.