home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Lookup 1.0d2 / Sources / CString.cp < prev   
Encoding:
Text File  |  1995-09-12  |  1.2 KB  |  57 lines  |  [TEXT/CWIE]

  1. /*
  2.     CString.cp
  3.  
  4.     Copyright © 1995 Alastair Rankine.
  5.     All Rights Reserved.
  6. */
  7.  
  8. #include "CString.h"
  9.  
  10. Str255 CString::sTempString[CString::kTempStringCount];
  11. unsigned short CString::sNextString = 0;
  12.  
  13. CString sEmptyString = "";
  14.  
  15. const StringPtr CString::ToPString() const
  16. {
  17.     StringPtr ret = sTempString[sNextString++ % kTempStringCount];
  18.     
  19.     ret[0] = (unsigned char)(length() > 255? 255 : length());
  20.     if(ret[0])
  21.         ::BlockMoveData(c_str(), ret + 1, ret[0]);
  22.     
  23.     return ret;
  24. }
  25.  
  26. CString & CString::ExtractFromAEDesc(const AEDesc & inDesc)
  27. //
  28. //    Prettymuch flogged stright from UExtractFromAEDesc::ToPString...
  29. //
  30. {
  31.     Handle    dataH;
  32.     AEDesc    coerceDesc = {typeNull, nil};
  33.     
  34.     if (inDesc.descriptorType == typeChar) {
  35.         dataH = inDesc.dataHandle;        // Descriptor is the type we want
  36.     
  37.     } else {                            // Try to coerce to the desired type
  38.         if (AECoerceDesc(&inDesc, typeChar, &coerceDesc) == noErr) {
  39.                                         // Coercion succeeded
  40.             dataH = coerceDesc.dataHandle;
  41.  
  42.         } else {                        // Coercion failed
  43.             ThrowOSErr_(errAETypeError);
  44.         }
  45.     }
  46.     
  47.     Int32 strLength = GetHandleSize(dataH);
  48.     assign(*dataH, strLength);
  49.     
  50.     if (coerceDesc.dataHandle != nil) {
  51.         AEDisposeDesc(&coerceDesc);
  52.     }
  53.     
  54.     return *this;
  55. }
  56.  
  57.