home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / COWS / Code / COWSStringNode.m < prev    next >
Encoding:
Text File  |  1994-03-06  |  1.4 KB  |  108 lines

  1. /*
  2.     Copyright (C) 1994 Sean Luke
  3.  
  4.     COWSStringNode.m
  5.     Version 1.0
  6.     Sean Luke
  7.     
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #import "COWSStringNode.h"
  14. #import "COWSInterpreter.h"
  15. #import <string.h>
  16. #import <stdlib.h>
  17.  
  18.  
  19. @implementation COWSStringNode
  20.  
  21. - init
  22.     {
  23.     id returnval=[super init];
  24.     string=    string=newstr("");
  25.     error=NO;
  26.     return returnval;
  27.     }
  28.     
  29. - (const char*) string
  30.     {
  31.     return string;
  32.     }
  33.     
  34. - setString:(const char*) this
  35.     {
  36.     if (this==NULL)
  37.         {
  38.         if (string!=NULL) free(string);
  39.         string=NULL;
  40.         return self;
  41.         }
  42.         
  43.     if (string!=NULL)
  44.         {
  45.         if (strlen(this)<=strlen(string))    // needn't allocate more space
  46.             {
  47.             strcpy(string,this);
  48.             return self;
  49.             }
  50.         // otherwise...
  51.         free(string);
  52.         }
  53.     string=newstr(this);
  54.     return self;
  55.     }
  56.     
  57. - setString:(const char*) this size:(int)this_size
  58.     {
  59.     if (this==NULL)
  60.         {
  61.         if (string!=NULL) free(string);
  62.         string=NULL;
  63.         return self;
  64.         }
  65.         
  66.     if (string!=NULL)
  67.         {
  68.         if (this_size+1<=strlen(string))    // needn't allocate more space
  69.             {
  70.             strncpy(string,this,this_size);
  71.             string[this_size]='\0';            // terminates it.
  72.             return self;
  73.             }
  74.         // otherwise...
  75.         free(string);
  76.         }
  77.     string=newstrn(this,this_size);
  78.     return self;
  79.     }
  80.     
  81. - free
  82.     {
  83.     if (string!=NULL)
  84.         {
  85.         free(string);
  86.         }
  87.     return [super free];
  88.     }
  89.  
  90. - printContents
  91.     {
  92.     printf ("\t#%s#\n",string);
  93.     return self;
  94.     }
  95.  
  96. - setError:(BOOL)true_or_false
  97.     {
  98.     error=true_or_false;
  99.     return self;
  100.     }
  101.     
  102.     
  103. - (BOOL) error
  104.     {
  105.     return error;
  106.     }
  107.  
  108. @end