home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-12 | 1.2 KB | 57 lines | [TEXT/CWIE] |
- /*
- CString.cp
-
- Copyright © 1995 Alastair Rankine.
- All Rights Reserved.
- */
-
- #include "CString.h"
-
- Str255 CString::sTempString[CString::kTempStringCount];
- unsigned short CString::sNextString = 0;
-
- CString sEmptyString = "";
-
- const StringPtr CString::ToPString() const
- {
- StringPtr ret = sTempString[sNextString++ % kTempStringCount];
-
- ret[0] = (unsigned char)(length() > 255? 255 : length());
- if(ret[0])
- ::BlockMoveData(c_str(), ret + 1, ret[0]);
-
- return ret;
- }
-
- CString & CString::ExtractFromAEDesc(const AEDesc & inDesc)
- //
- // Prettymuch flogged stright from UExtractFromAEDesc::ToPString...
- //
- {
- Handle dataH;
- AEDesc coerceDesc = {typeNull, nil};
-
- if (inDesc.descriptorType == typeChar) {
- dataH = inDesc.dataHandle; // Descriptor is the type we want
-
- } else { // Try to coerce to the desired type
- if (AECoerceDesc(&inDesc, typeChar, &coerceDesc) == noErr) {
- // Coercion succeeded
- dataH = coerceDesc.dataHandle;
-
- } else { // Coercion failed
- ThrowOSErr_(errAETypeError);
- }
- }
-
- Int32 strLength = GetHandleSize(dataH);
- assign(*dataH, strLength);
-
- if (coerceDesc.dataHandle != nil) {
- AEDisposeDesc(&coerceDesc);
- }
-
- return *this;
- }
-
-