12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753 |
- /* ====================================================================
- * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
- *
- * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * openssl-core@openssl.org.
- *
- * 5. Products derived from this software may not be called "OpenSSL"
- * nor may "OpenSSL" appear in their names without prior written
- * permission of the OpenSSL Project.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- * "This product includes software developed by the OpenSSL Project
- * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
- *
- * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- * ====================================================================
- *
- * This product includes cryptographic software written by Eric Young
- * (eay@cryptsoft.com). This product includes software written by Tim
- * Hudson (tjh@cryptsoft.com).
- *
- */
-
-
-
- #include "CPStringUtils.hpp"
- #include "ErrorHandling.hpp"
- #define kNumberFormatString "\p########0.00#######;-########0.00#######"
- // Useful utility functions which could be optimized a whole lot
- void CopyPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
- {
- int i,numPChars;
- if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
- {
- numPChars = thePStr[0];
-
- for (i = 0;;i++)
- {
- if (i >= numPChars || i >= maxCStrLength - 1)
- {
- theCStr[i] = 0;
-
- break;
- }
-
- else
- {
- theCStr[i] = thePStr[i + 1];
- }
- }
- }
- }
- void CopyPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
- {
- int theMaxDstStrLength;
-
- theMaxDstStrLength = maxDstStrLength;
-
-
- if (theDstPStr != nil && theSrcPStr != nil && theMaxDstStrLength > 0)
- {
- if (theMaxDstStrLength > 255)
- {
- theMaxDstStrLength = 255;
- }
-
-
- if (theMaxDstStrLength - 1 < theSrcPStr[0])
- {
- BlockMove(theSrcPStr + 1,theDstPStr + 1,theMaxDstStrLength - 1);
-
- theDstPStr[0] = theMaxDstStrLength - 1;
- }
-
- else
- {
- BlockMove(theSrcPStr,theDstPStr,theSrcPStr[0] + 1);
- }
- }
- }
- void CopyCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxDstStrLength)
- {
- int i;
- if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
- {
- for (i = 0;;i++)
- {
- if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1)
- {
- theDstCStr[i] = 0;
-
- break;
- }
-
- else
- {
- theDstCStr[i] = theSrcCStr[i];
- }
- }
- }
- }
- void CopyCSubstrToCStr(const char *theSrcCStr,const int maxCharsToCopy,char *theDstCStr,const int maxDstStrLength)
- {
- int i;
- if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
- {
- for (i = 0;;i++)
- {
- if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1 || i >= maxCharsToCopy)
- {
- theDstCStr[i] = 0;
-
- break;
- }
-
- else
- {
- theDstCStr[i] = theSrcCStr[i];
- }
- }
- }
- }
- void CopyCSubstrToPStr(const char *theSrcCStr,const int maxCharsToCopy,unsigned char *theDstPStr,const int maxDstStrLength)
- {
- int i;
- int theMaxDstStrLength;
-
- theMaxDstStrLength = maxDstStrLength;
- if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
- {
- if (theMaxDstStrLength > 255)
- {
- theMaxDstStrLength = 255;
- }
-
-
- for (i = 0;;i++)
- {
- if (theSrcCStr[i] == 0 || i >= theMaxDstStrLength - 1 || i >= maxCharsToCopy)
- {
- theDstPStr[0] = i;
-
- break;
- }
-
- else
- {
- theDstPStr[i + 1] = theSrcCStr[i];
- }
- }
- }
- }
- void CopyCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
- {
- int i;
- int theMaxDstStrLength;
-
- theMaxDstStrLength = maxDstStrLength;
- if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
- {
- if (theMaxDstStrLength > 255)
- {
- theMaxDstStrLength = 255;
- }
-
-
- for (i = 0;;i++)
- {
- if (i >= theMaxDstStrLength - 1 || theSrcCStr[i] == 0)
- {
- theDstPStr[0] = i;
-
- break;
- }
-
- else
- {
- theDstPStr[i + 1] = theSrcCStr[i];
- }
- }
- }
- }
- void ConcatPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
- {
- int i,numPChars,cStrLength;
- if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
- {
- for (cStrLength = 0;theCStr[cStrLength] != 0;cStrLength++)
- {
-
- }
-
- numPChars = thePStr[0];
-
-
- for (i = 0;;i++)
- {
- if (i >= numPChars || cStrLength >= maxCStrLength - 1)
- {
- theCStr[cStrLength++] = 0;
-
- break;
- }
-
- else
- {
- theCStr[cStrLength++] = thePStr[i + 1];
- }
- }
- }
- }
- void ConcatPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
- {
- int theMaxDstStrLength;
-
- theMaxDstStrLength = maxDstStrLength;
-
- if (theSrcPStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
- {
- if (theMaxDstStrLength > 255)
- {
- theMaxDstStrLength = 255;
- }
-
-
- if (theMaxDstStrLength - theDstPStr[0] - 1 < theSrcPStr[0])
- {
- BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theMaxDstStrLength - 1 - theDstPStr[0]);
-
- theDstPStr[0] = theMaxDstStrLength - 1;
- }
-
- else
- {
- BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theSrcPStr[0]);
-
- theDstPStr[0] += theSrcPStr[0];
- }
- }
- }
- void ConcatCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
- {
- int i,thePStrLength;
- int theMaxDstStrLength;
-
- theMaxDstStrLength = maxDstStrLength;
- if (theSrcCStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
- {
- if (theMaxDstStrLength > 255)
- {
- theMaxDstStrLength = 255;
- }
-
-
- thePStrLength = theDstPStr[0];
-
- for (i = 0;;i++)
- {
- if (theSrcCStr[i] == 0 || thePStrLength >= theMaxDstStrLength - 1)
- {
- theDstPStr[0] = thePStrLength;
-
- break;
- }
-
- else
- {
- theDstPStr[thePStrLength + 1] = theSrcCStr[i];
-
- thePStrLength++;
- }
- }
- }
- }
- void ConcatCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxCStrLength)
- {
- int cStrLength;
- if (theSrcCStr != nil && theDstCStr != nil && maxCStrLength > 0)
- {
- for (cStrLength = 0;theDstCStr[cStrLength] != 0;cStrLength++)
- {
-
- }
-
- for (;;)
- {
- if (*theSrcCStr == 0 || cStrLength >= maxCStrLength - 1)
- {
- theDstCStr[cStrLength++] = 0;
-
- break;
- }
-
- else
- {
- theDstCStr[cStrLength++] = *theSrcCStr++;
- }
- }
- }
- }
- void ConcatCharToCStr(const char theChar,char *theDstCStr,const int maxCStrLength)
- {
- int cStrLength;
- if (theDstCStr != nil && maxCStrLength > 0)
- {
- cStrLength = CStrLength(theDstCStr);
-
- if (cStrLength < maxCStrLength - 1)
- {
- theDstCStr[cStrLength++] = theChar;
- theDstCStr[cStrLength++] = '\0';
- }
- }
- }
- void ConcatCharToPStr(const char theChar,unsigned char *theDstPStr,const int maxPStrLength)
- {
- int pStrLength;
- if (theDstPStr != nil && maxPStrLength > 0)
- {
- pStrLength = PStrLength(theDstPStr);
-
- if (pStrLength < maxPStrLength - 1 && pStrLength < 255)
- {
- theDstPStr[pStrLength + 1] = theChar;
- theDstPStr[0] += 1;
- }
- }
- }
- int CompareCStrs(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
- {
- int returnValue;
- char firstChar,secondChar;
-
- returnValue = 0;
-
-
- if (theFirstCStr != nil && theSecondCStr != nil)
- {
- for (;;)
- {
- firstChar = *theFirstCStr;
- secondChar = *theSecondCStr;
-
- if (ignoreCase == true)
- {
- if (firstChar >= 'A' && firstChar <= 'Z')
- {
- firstChar = 'a' + (firstChar - 'A');
- }
-
- if (secondChar >= 'A' && secondChar <= 'Z')
- {
- secondChar = 'a' + (secondChar - 'A');
- }
- }
-
-
- if (firstChar == 0 && secondChar != 0)
- {
- returnValue = -1;
-
- break;
- }
-
- else if (firstChar != 0 && secondChar == 0)
- {
- returnValue = 1;
-
- break;
- }
-
- else if (firstChar == 0 && secondChar == 0)
- {
- returnValue = 0;
-
- break;
- }
-
- else if (firstChar < secondChar)
- {
- returnValue = -1;
-
- break;
- }
-
- else if (firstChar > secondChar)
- {
- returnValue = 1;
-
- break;
- }
-
- theFirstCStr++;
- theSecondCStr++;
- }
- }
-
-
- return(returnValue);
- }
- Boolean CStrsAreEqual(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
- {
- if (CompareCStrs(theFirstCStr,theSecondCStr,ignoreCase) == 0)
- {
- return true;
- }
-
- else
- {
- return false;
- }
- }
- Boolean PStrsAreEqual(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
- {
- if (ComparePStrs(theFirstPStr,theSecondPStr,ignoreCase) == 0)
- {
- return true;
- }
-
- else
- {
- return false;
- }
- }
- int ComparePStrs(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
- {
- int i,returnValue;
- char firstChar,secondChar;
-
- returnValue = 0;
-
-
- if (theFirstPStr != nil && theSecondPStr != nil)
- {
- for (i = 1;;i++)
- {
- firstChar = theFirstPStr[i];
- secondChar = theSecondPStr[i];
- if (ignoreCase == true)
- {
- if (firstChar >= 'A' && firstChar <= 'Z')
- {
- firstChar = 'a' + (firstChar - 'A');
- }
-
- if (secondChar >= 'A' && secondChar <= 'Z')
- {
- secondChar = 'a' + (secondChar - 'A');
- }
- }
- if (theFirstPStr[0] < i && theSecondPStr[0] >= i)
- {
- returnValue = -1;
-
- break;
- }
-
- else if (theFirstPStr[0] >= i && theSecondPStr[0] < i)
- {
- returnValue = 1;
-
- break;
- }
-
- else if (theFirstPStr[0] < i && theSecondPStr[0] < i)
- {
- returnValue = 0;
-
- break;
- }
-
- else if (firstChar < secondChar)
- {
- returnValue = -1;
-
- break;
- }
-
- else if (firstChar > secondChar)
- {
- returnValue = 1;
-
- break;
- }
- }
- }
-
-
- return(returnValue);
- }
- int CompareCStrToPStr(const char *theCStr,const unsigned char *thePStr,const Boolean ignoreCase)
- {
- int returnValue;
- char tempString[256];
-
- returnValue = 0;
-
- if (theCStr != nil && thePStr != nil)
- {
- CopyPStrToCStr(thePStr,tempString,sizeof(tempString));
-
- returnValue = CompareCStrs(theCStr,tempString,ignoreCase);
- }
-
-
- return(returnValue);
- }
- void ConcatLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
- {
- Str255 theStr255;
- NumToString(theNum,theStr255);
- if (numDigits > 0)
- {
- int charsToInsert;
-
-
- charsToInsert = numDigits - PStrLength(theStr255);
-
- if (charsToInsert > 0)
- {
- char tempString[256];
-
- CopyCStrToCStr("",tempString,sizeof(tempString));
-
- for (;charsToInsert > 0;charsToInsert--)
- {
- ConcatCStrToCStr("0",tempString,sizeof(tempString));
- }
-
- ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
-
- CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
- }
- }
- ConcatPStrToCStr(theStr255,theCStr,maxCStrLength);
- }
- void ConcatLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
- {
- Str255 theStr255;
- NumToString(theNum,theStr255);
- if (numDigits > 0)
- {
- int charsToInsert;
-
-
- charsToInsert = numDigits - PStrLength(theStr255);
-
- if (charsToInsert > 0)
- {
- char tempString[256];
-
- CopyCStrToCStr("",tempString,sizeof(tempString));
-
- for (;charsToInsert > 0;charsToInsert--)
- {
- ConcatCStrToCStr("0",tempString,sizeof(tempString));
- }
-
- ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
-
- CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
- }
- }
- ConcatPStrToPStr(theStr255,thePStr,maxPStrLength);
- }
- void CopyCStrAndConcatLongIntToCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
- {
- CopyCStrToCStr(theSrcCStr,theDstCStr,maxDstStrLength);
-
- ConcatLongIntToCStr(theNum,theDstCStr,maxDstStrLength);
- }
- void CopyLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
- {
- Str255 theStr255;
- NumToString(theNum,theStr255);
- if (numDigits > 0)
- {
- int charsToInsert;
-
-
- charsToInsert = numDigits - PStrLength(theStr255);
-
- if (charsToInsert > 0)
- {
- char tempString[256];
-
- CopyCStrToCStr("",tempString,sizeof(tempString));
-
- for (;charsToInsert > 0;charsToInsert--)
- {
- ConcatCStrToCStr("0",tempString,sizeof(tempString));
- }
-
- ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
-
- CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
- }
- }
- CopyPStrToCStr(theStr255,theCStr,maxCStrLength);
- }
- void CopyUnsignedLongIntToCStr(const unsigned long theNum,char *theCStr,const int maxCStrLength)
- {
- char tempString[256];
- int srcCharIndex,dstCharIndex;
- unsigned long tempNum,quotient,remainder;
-
- if (theNum == 0)
- {
- CopyCStrToCStr("0",theCStr,maxCStrLength);
- }
-
- else
- {
- srcCharIndex = 0;
-
- tempNum = theNum;
-
- for (;;)
- {
- if (srcCharIndex >= sizeof(tempString) - 1 || tempNum == 0)
- {
- for (dstCharIndex = 0;;)
- {
- if (dstCharIndex >= maxCStrLength - 1 || srcCharIndex <= 0)
- {
- theCStr[dstCharIndex] = 0;
-
- break;
- }
-
- theCStr[dstCharIndex++] = tempString[--srcCharIndex];
- }
-
- break;
- }
-
- quotient = tempNum / 10;
-
- remainder = tempNum - (quotient * 10);
-
- tempString[srcCharIndex] = '0' + remainder;
-
- srcCharIndex++;
-
- tempNum = quotient;
- }
- }
- }
- void CopyLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
- {
- char tempString[256];
- CopyLongIntToCStr(theNum,tempString,sizeof(tempString),numDigits);
-
- CopyCStrToPStr(tempString,thePStr,maxPStrLength);
- }
- OSErr CopyLongIntToNewHandle(const long inTheLongInt,Handle *theHandle)
- {
- OSErr errCode = noErr;
- char tempString[32];
-
-
- CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
-
- errCode = CopyCStrToNewHandle(tempString,theHandle);
- return(errCode);
- }
- OSErr CopyLongIntToExistingHandle(const long inTheLongInt,Handle theHandle)
- {
- OSErr errCode = noErr;
- char tempString[32];
-
-
- CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
-
- errCode = CopyCStrToExistingHandle(tempString,theHandle);
- return(errCode);
- }
- OSErr CopyCStrToExistingHandle(const char *theCString,Handle theHandle)
- {
- OSErr errCode = noErr;
- long stringLength;
-
- if (theCString == nil)
- {
- SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theCString == nil"));
- }
- if (theHandle == nil)
- {
- SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theHandle == nil"));
- }
- if (*theHandle == nil)
- {
- SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, *theHandle == nil"));
- }
- stringLength = CStrLength(theCString) + 1;
-
- SetHandleSize(theHandle,stringLength);
-
- if (GetHandleSize(theHandle) < stringLength)
- {
- SetErrorMessageAndLongIntAndBail("CopyCStrToExistingHandle: Can't set Handle size, MemError() = ",MemError());
- }
-
-
- ::BlockMove(theCString,*theHandle,stringLength);
-
- EXITPOINT:
-
- return(errCode);
- }
- OSErr CopyCStrToNewHandle(const char *theCString,Handle *theHandle)
- {
- OSErr errCode = noErr;
- long stringLength;
-
- if (theCString == nil)
- {
- SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theCString == nil"));
- }
- if (theHandle == nil)
- {
- SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theHandle == nil"));
- }
- stringLength = CStrLength(theCString) + 1;
-
- *theHandle = NewHandle(stringLength);
-
- if (*theHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("CopyCStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
-
- ::BlockMove(theCString,**theHandle,stringLength);
-
- EXITPOINT:
-
- return(errCode);
- }
- OSErr CopyPStrToNewHandle(const unsigned char *thePString,Handle *theHandle)
- {
- OSErr errCode = noErr;
- long stringLength;
-
- if (thePString == nil)
- {
- SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, thePString == nil"));
- }
- if (theHandle == nil)
- {
- SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, theHandle == nil"));
- }
- stringLength = PStrLength(thePString) + 1;
-
- *theHandle = NewHandle(stringLength);
-
- if (*theHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("CopyPStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
-
- if (stringLength > 1)
- {
- BlockMove(thePString + 1,**theHandle,stringLength - 1);
- }
-
- (**theHandle)[stringLength - 1] = 0;
-
- EXITPOINT:
-
- return(errCode);
- }
- OSErr AppendPStrToHandle(const unsigned char *thePString,Handle theHandle,long *currentLength)
- {
- OSErr errCode = noErr;
- char tempString[256];
-
- CopyPStrToCStr(thePString,tempString,sizeof(tempString));
-
- errCode = AppendCStrToHandle(tempString,theHandle,currentLength);
-
- EXITPOINT:
-
- return(errCode);
- }
- OSErr AppendCStrToHandle(const char *theCString,Handle theHandle,long *currentLength,long *maxLength)
- {
- OSErr errCode = noErr;
- long handleMaxLength,handleCurrentLength,stringLength,byteCount;
- if (theCString == nil)
- {
- SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theCString == nil"));
- }
- if (theHandle == nil)
- {
- SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theHandle == nil"));
- }
-
-
- if (maxLength != nil)
- {
- handleMaxLength = *maxLength;
- }
-
- else
- {
- handleMaxLength = GetHandleSize(theHandle);
- }
-
-
- if (currentLength != nil && *currentLength >= 0)
- {
- handleCurrentLength = *currentLength;
- }
-
- else
- {
- handleCurrentLength = CStrLength(*theHandle);
- }
-
-
- stringLength = CStrLength(theCString);
-
- byteCount = handleCurrentLength + stringLength + 1;
-
- if (byteCount > handleMaxLength)
- {
- SetHandleSize(theHandle,handleCurrentLength + stringLength + 1);
-
- if (maxLength != nil)
- {
- *maxLength = GetHandleSize(theHandle);
-
- handleMaxLength = *maxLength;
- }
-
- else
- {
- handleMaxLength = GetHandleSize(theHandle);
- }
- if (byteCount > handleMaxLength)
- {
- SetErrorMessageAndLongIntAndBail("AppendCStrToHandle: Can't increase Handle allocation, MemError() = ",MemError());
- }
- }
-
-
- BlockMove(theCString,*theHandle + handleCurrentLength,stringLength + 1);
-
-
- if (currentLength != nil)
- {
- *currentLength += stringLength;
- }
- errCode = noErr;
-
-
- EXITPOINT:
- return(errCode);
- }
- OSErr AppendCharsToHandle(const char *theChars,const int numChars,Handle theHandle,long *currentLength,long *maxLength)
- {
- OSErr errCode = noErr;
- long handleMaxLength,handleCurrentLength,byteCount;
- if (theChars == nil)
- {
- SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theChars == nil"));
- }
- if (theHandle == nil)
- {
- SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theHandle == nil"));
- }
-
-
- if (maxLength != nil)
- {
- handleMaxLength = *maxLength;
- }
-
- else
- {
- handleMaxLength = GetHandleSize(theHandle);
- }
-
-
- if (currentLength != nil && *currentLength >= 0)
- {
- handleCurrentLength = *currentLength;
- }
-
- else
- {
- handleCurrentLength = CStrLength(*theHandle);
- }
-
-
- byteCount = handleCurrentLength + numChars + 1;
-
- if (byteCount > handleMaxLength)
- {
- SetHandleSize(theHandle,handleCurrentLength + numChars + 1);
-
- if (maxLength != nil)
- {
- *maxLength = GetHandleSize(theHandle);
-
- handleMaxLength = *maxLength;
- }
-
- else
- {
- handleMaxLength = GetHandleSize(theHandle);
- }
- if (byteCount > handleMaxLength)
- {
- SetErrorMessageAndLongIntAndBail("AppendCharsToHandle: Can't increase Handle allocation, MemError() = ",MemError());
- }
- }
-
-
- BlockMove(theChars,*theHandle + handleCurrentLength,numChars);
-
- (*theHandle)[handleCurrentLength + numChars] = '\0';
-
- if (currentLength != nil)
- {
- *currentLength += numChars;
- }
- errCode = noErr;
-
-
- EXITPOINT:
- return(errCode);
- }
- OSErr AppendLongIntToHandle(const long inTheLongInt,Handle theHandle,long *currentLength)
- {
- OSErr errCode = noErr;
- char tempString[32];
-
-
- CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
-
- errCode = AppendCStrToHandle(tempString,theHandle,currentLength);
- return(errCode);
- }
- long CStrLength(const char *theCString)
- {
- long cStrLength = 0;
-
- if (theCString != nil)
- {
- for (cStrLength = 0;theCString[cStrLength] != 0;cStrLength++)
- {
-
- }
- }
-
-
- return(cStrLength);
- }
- long PStrLength(const unsigned char *thePString)
- {
- long pStrLength = 0;
-
- if (thePString != nil)
- {
- pStrLength = thePString[0];
- }
-
-
- return(pStrLength);
- }
- void ZeroMem(void *theMemPtr,const unsigned long numBytes)
- {
- unsigned char *theBytePtr;
- unsigned long *theLongPtr;
- unsigned long numSingleBytes;
- unsigned long theNumBytes;
-
- theNumBytes = numBytes;
-
- if (theMemPtr != nil && theNumBytes > 0)
- {
- theBytePtr = (unsigned char *) theMemPtr;
-
- numSingleBytes = (unsigned long) theBytePtr & 0x0003;
-
- while (numSingleBytes > 0)
- {
- *theBytePtr++ = 0;
-
- theNumBytes--;
- numSingleBytes--;
- }
-
- theLongPtr = (unsigned long *) theBytePtr;
-
- while (theNumBytes >= 4)
- {
- *theLongPtr++ = 0;
-
- theNumBytes -= 4;
- }
-
-
- theBytePtr = (unsigned char *) theLongPtr;
-
- while (theNumBytes > 0)
- {
- *theBytePtr++ = 0;
-
- theNumBytes--;
- }
- }
- }
- char *FindCharInCStr(const char theChar,const char *theCString)
- {
- char *theStringSearchPtr;
-
- theStringSearchPtr = (char *) theCString;
-
- if (theStringSearchPtr != nil)
- {
- while (*theStringSearchPtr != '\0' && *theStringSearchPtr != theChar)
- {
- theStringSearchPtr++;
- }
-
- if (*theStringSearchPtr == '\0')
- {
- theStringSearchPtr = nil;
- }
- }
-
- return(theStringSearchPtr);
- }
- long FindCharOffsetInCStr(const char theChar,const char *theCString,const Boolean inIgnoreCase)
- {
- long theOffset = -1;
- if (theCString != nil)
- {
- theOffset = 0;
-
- if (inIgnoreCase)
- {
- char searchChar = theChar;
-
- if (searchChar >= 'a' && searchChar <= 'z')
- {
- searchChar = searchChar - 'a' + 'A';
- }
-
-
- while (*theCString != 0)
- {
- char currentChar = *theCString;
-
- if (currentChar >= 'a' && currentChar <= 'z')
- {
- currentChar = currentChar - 'a' + 'A';
- }
-
- if (currentChar == searchChar)
- {
- break;
- }
-
- theCString++;
- theOffset++;
- }
- }
-
- else
- {
- while (*theCString != 0 && *theCString != theChar)
- {
- theCString++;
- theOffset++;
- }
- }
-
- if (*theCString == 0)
- {
- theOffset = -1;
- }
- }
-
- return(theOffset);
- }
- long FindCStrOffsetInCStr(const char *theCSubstring,const char *theCString,const Boolean inIgnoreCase)
- {
- long theOffset = -1;
- if (theCSubstring != nil && theCString != nil)
- {
- for (theOffset = 0;;theOffset++)
- {
- if (theCString[theOffset] == 0)
- {
- theOffset = -1;
-
- goto EXITPOINT;
- }
-
-
- for (const char *tempSubstringPtr = theCSubstring,*tempCStringPtr = theCString + theOffset;;tempSubstringPtr++,tempCStringPtr++)
- {
- if (*tempSubstringPtr == 0)
- {
- goto EXITPOINT;
- }
-
- else if (*tempCStringPtr == 0)
- {
- break;
- }
-
- char searchChar = *tempSubstringPtr;
- char currentChar = *tempCStringPtr;
-
- if (inIgnoreCase && searchChar >= 'a' && searchChar <= 'z')
- {
- searchChar = searchChar - 'a' + 'A';
- }
-
- if (inIgnoreCase && currentChar >= 'a' && currentChar <= 'z')
- {
- currentChar = currentChar - 'a' + 'A';
- }
-
- if (currentChar != searchChar)
- {
- break;
- }
- }
- }
-
- theOffset = -1;
- }
- EXITPOINT:
-
- return(theOffset);
- }
- void InsertCStrIntoCStr(const char *theSrcCStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength)
- {
- int currentLength;
- int insertLength;
- int numCharsToInsert;
- int numCharsToShift;
-
- if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
- {
- currentLength = CStrLength(theDstCStr);
-
- insertLength = CStrLength(theSrcCStr);
-
- if (theInsertionOffset + insertLength < maxDstStrLength - 1)
- {
- numCharsToInsert = insertLength;
- }
-
- else
- {
- numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
- }
-
- if (numCharsToInsert + currentLength < maxDstStrLength - 1)
- {
- numCharsToShift = currentLength - theInsertionOffset;
- }
-
- else
- {
- numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
- }
-
- if (numCharsToShift > 0)
- {
- BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
- }
-
- if (numCharsToInsert > 0)
- {
- BlockMove(theSrcCStr,theDstCStr + theInsertionOffset,numCharsToInsert);
- }
-
- theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
- }
- }
- void InsertPStrIntoCStr(const unsigned char *theSrcPStr,const int theInsertionOffset,char *theDstCStr,const int maxDstStrLength)
- {
- int currentLength;
- int insertLength;
- int numCharsToInsert;
- int numCharsToShift;
-
- if (theDstCStr != nil && theSrcPStr != nil && maxDstStrLength > 0 && theInsertionOffset < maxDstStrLength - 1)
- {
- currentLength = CStrLength(theDstCStr);
-
- insertLength = PStrLength(theSrcPStr);
-
- if (theInsertionOffset + insertLength < maxDstStrLength - 1)
- {
- numCharsToInsert = insertLength;
- }
-
- else
- {
- numCharsToInsert = maxDstStrLength - 1 - theInsertionOffset;
- }
-
- if (numCharsToInsert + currentLength < maxDstStrLength - 1)
- {
- numCharsToShift = currentLength - theInsertionOffset;
- }
-
- else
- {
- numCharsToShift = maxDstStrLength - 1 - theInsertionOffset - numCharsToInsert;
- }
-
- if (numCharsToShift > 0)
- {
- BlockMove(theDstCStr + theInsertionOffset,theDstCStr + theInsertionOffset + numCharsToInsert,numCharsToShift);
- }
-
- if (numCharsToInsert > 0)
- {
- BlockMove(theSrcPStr + 1,theDstCStr + theInsertionOffset,numCharsToInsert);
- }
-
- theDstCStr[theInsertionOffset + numCharsToInsert + numCharsToShift] = 0;
- }
- }
- OSErr InsertCStrIntoHandle(const char *theCString,Handle theHandle,const long inInsertOffset)
- {
- OSErr errCode;
- int currentLength;
- int insertLength;
-
- SetErrorMessageAndBailIfNil(theCString,"InsertCStrIntoHandle: Bad parameter, theCString == nil");
- SetErrorMessageAndBailIfNil(theHandle,"InsertCStrIntoHandle: Bad parameter, theHandle == nil");
-
- currentLength = CStrLength(*theHandle);
-
- if (currentLength + 1 > ::GetHandleSize(theHandle))
- {
- SetErrorMessageAndBail("InsertCStrIntoHandle: Handle has been overflowed");
- }
-
- if (inInsertOffset > currentLength)
- {
- SetErrorMessageAndBail("InsertCStrIntoHandle: Insertion offset is greater than string length");
- }
-
- insertLength = CStrLength(theCString);
-
- ::SetHandleSize(theHandle,currentLength + 1 + insertLength);
-
- if (::GetHandleSize(theHandle) < currentLength + 1 + insertLength)
- {
- SetErrorMessageAndLongIntAndBail("InsertCStrIntoHandle: Can't expand storage for Handle, MemError() = ",MemError());
- }
-
- ::BlockMove(*theHandle + inInsertOffset,*theHandle + inInsertOffset + insertLength,currentLength - inInsertOffset + 1);
-
- ::BlockMove(theCString,*theHandle + inInsertOffset,insertLength);
- errCode = noErr;
-
-
- EXITPOINT:
- return(errCode);
- }
- void CopyCStrAndInsert1LongIntIntoCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
- {
- CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,nil,theNum,theDstCStr,maxDstStrLength);
- }
- void CopyCStrAndInsert2LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,char *theDstCStr,const int maxDstStrLength)
- {
- const long theLongInts[] = { long1,long2 };
- CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);
- }
- void CopyCStrAndInsert3LongIntsIntoCStr(const char *theSrcCStr,const long long1,const long long2,const long long3,char *theDstCStr,const int maxDstStrLength)
- {
- const long theLongInts[] = { long1,long2,long3 };
- CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,nil,theLongInts,theDstCStr,maxDstStrLength);
- }
- void CopyCStrAndInsertCStrIntoCStr(const char *theSrcCStr,const char *theInsertCStr,char *theDstCStr,const int maxDstStrLength)
- {
- const char *theCStrs[2] = { theInsertCStr,nil };
- CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,nil,theDstCStr,maxDstStrLength);
- }
- void CopyCStrAndInsertCStrLongIntIntoCStr(const char *theSrcCStr,const char *theInsertCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
- {
- const char *theCStrs[2] = { theInsertCStr,nil };
- const long theLongInts[1] = { theNum };
- CopyCStrAndInsertCStrsLongIntsIntoCStr(theSrcCStr,theCStrs,theLongInts,theDstCStr,maxDstStrLength);
- }
- void CopyCStrAndInsertCStrsLongIntsIntoCStr(const char *theSrcCStr,const char **theInsertCStrs,const long *theLongInts,char *theDstCStr,const int maxDstStrLength)
- {
- int dstCharIndex,srcCharIndex,theMaxDstStrLength;
- int theCStrIndex = 0;
- int theLongIntIndex = 0;
-
- theMaxDstStrLength = maxDstStrLength;
-
- if (theDstCStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
- {
- dstCharIndex = 0;
-
- srcCharIndex = 0;
-
-
- // Allow room for NULL at end of string
-
- theMaxDstStrLength--;
-
-
- for (;;)
- {
- // Hit end of buffer?
-
- if (dstCharIndex >= theMaxDstStrLength)
- {
- theDstCStr[dstCharIndex++] = 0;
-
- goto EXITPOINT;
- }
-
- // End of source string?
-
- else if (theSrcCStr[srcCharIndex] == 0)
- {
- theDstCStr[dstCharIndex++] = 0;
-
- goto EXITPOINT;
- }
-
- // Did we find a '%s'?
-
- else if (theInsertCStrs != nil && theInsertCStrs[theCStrIndex] != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 's')
- {
- // Skip over the '%s'
-
- srcCharIndex += 2;
-
-
- // Terminate the dest string and then concat the string
-
- theDstCStr[dstCharIndex] = 0;
-
- ConcatCStrToCStr(theInsertCStrs[theCStrIndex],theDstCStr,theMaxDstStrLength);
-
- dstCharIndex = CStrLength(theDstCStr);
-
- theCStrIndex++;
- }
-
- // Did we find a '%ld'?
-
- else if (theLongInts != nil && theSrcCStr[srcCharIndex] == '%' && theSrcCStr[srcCharIndex + 1] == 'l' && theSrcCStr[srcCharIndex + 2] == 'd')
- {
- // Skip over the '%ld'
-
- srcCharIndex += 3;
-
-
- // Terminate the dest string and then concat the number
-
- theDstCStr[dstCharIndex] = 0;
-
- ConcatLongIntToCStr(theLongInts[theLongIntIndex],theDstCStr,theMaxDstStrLength);
-
- theLongIntIndex++;
-
- dstCharIndex = CStrLength(theDstCStr);
- }
-
- else
- {
- theDstCStr[dstCharIndex++] = theSrcCStr[srcCharIndex++];
- }
- }
- }
- EXITPOINT:
- return;
- }
- OSErr CopyCStrAndInsertCStrLongIntIntoHandle(const char *theSrcCStr,const char *theInsertCStr,const long theNum,Handle *theHandle)
- {
- OSErr errCode;
- long byteCount;
-
- if (theHandle != nil)
- {
- byteCount = CStrLength(theSrcCStr) + CStrLength(theInsertCStr) + 32;
-
- *theHandle = NewHandle(byteCount);
-
- if (*theHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("CopyCStrAndInsertCStrLongIntIntoHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
-
- HLock(*theHandle);
-
- CopyCStrAndInsertCStrLongIntIntoCStr(theSrcCStr,theInsertCStr,theNum,**theHandle,byteCount);
-
- HUnlock(*theHandle);
- }
-
- errCode = noErr;
-
-
- EXITPOINT:
- return(errCode);
- }
- OSErr CopyIndexedWordToCStr(char *theSrcCStr,int whichWord,char *theDstCStr,int maxDstCStrLength)
- {
- OSErr errCode;
- char *srcCharPtr,*dstCharPtr;
- int wordCount;
- int byteCount;
- if (theSrcCStr == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theSrcCStr == nil"));
- }
-
- if (theDstCStr == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, theDstCStr == nil"));
- }
-
- if (whichWord < 0)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, whichWord < 0"));
- }
-
- if (maxDstCStrLength <= 0)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToCStr: Bad parameter, maxDstCStrLength <= 0"));
- }
-
- *theDstCStr = '\0';
-
- srcCharPtr = theSrcCStr;
- while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
- {
- srcCharPtr++;
- }
-
- for (wordCount = 0;wordCount < whichWord;wordCount++)
- {
- while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')
- {
- srcCharPtr++;
- }
-
- if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
- {
- errCode = noErr;
-
- goto EXITPOINT;
- }
- while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
- {
- srcCharPtr++;
- }
-
- if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
- {
- errCode = noErr;
-
- goto EXITPOINT;
- }
- }
- dstCharPtr = theDstCStr;
- byteCount = 0;
-
-
- for(;;)
- {
- if (byteCount >= maxDstCStrLength - 1 || *srcCharPtr == '\0' || *srcCharPtr == ' ' || *srcCharPtr == '\t' || *srcCharPtr == '\r' || *srcCharPtr == '\n')
- {
- *dstCharPtr = '\0';
- break;
- }
-
- *dstCharPtr++ = *srcCharPtr++;
-
- byteCount++;
- }
- errCode = noErr;
- EXITPOINT:
- return(errCode);
- }
- OSErr CopyIndexedWordToNewHandle(char *theSrcCStr,int whichWord,Handle *outTheHandle)
- {
- OSErr errCode;
- char *srcCharPtr;
- int wordCount;
- int byteCount;
- if (theSrcCStr == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, theSrcCStr == nil"));
- }
-
- if (outTheHandle == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, outTheHandle == nil"));
- }
-
- if (whichWord < 0)
- {
- SetErrorMessageAndBail(("CopyIndexedWordToNewHandle: Bad parameter, whichWord < 0"));
- }
-
- *outTheHandle = nil;
-
- srcCharPtr = theSrcCStr;
- while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
- {
- srcCharPtr++;
- }
-
- for (wordCount = 0;wordCount < whichWord;wordCount++)
- {
- while (*srcCharPtr != ' ' && *srcCharPtr != '\t' && *srcCharPtr != '\r' && *srcCharPtr != '\n' && *srcCharPtr != '\0')
- {
- srcCharPtr++;
- }
-
- if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
- {
- break;
- }
- while (*srcCharPtr == ' ' || *srcCharPtr == '\t')
- {
- srcCharPtr++;
- }
-
- if (*srcCharPtr == '\r' || *srcCharPtr == '\n' || *srcCharPtr == '\0')
- {
- break;
- }
- }
- for (byteCount = 0;;byteCount++)
- {
- if (srcCharPtr[byteCount] == ' ' || srcCharPtr[byteCount] == '\t' || srcCharPtr[byteCount] == '\r' || srcCharPtr[byteCount] == '\n' || srcCharPtr[byteCount] == '\0')
- {
- break;
- }
- }
-
- *outTheHandle = NewHandle(byteCount + 1);
-
- if (*outTheHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("CopyIndexedWordToNewHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
-
- ::BlockMove(srcCharPtr,**outTheHandle,byteCount);
-
- (**outTheHandle)[byteCount] = '\0';
- errCode = noErr;
- EXITPOINT:
- return(errCode);
- }
- OSErr CopyIndexedLineToCStr(const char *theSrcCStr,int inWhichLine,int *lineEndIndex,Boolean *gotLastLine,char *theDstCStr,const int maxDstCStrLength)
- {
- OSErr errCode;
- int theCurrentLine;
- int theCurrentLineOffset;
- int theEOSOffset;
- if (theSrcCStr == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theSrcCStr == nil"));
- }
-
- if (theDstCStr == nil)
- {
- SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, theDstCStr == nil"));
- }
-
- if (inWhichLine < 0)
- {
- SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, inWhichLine < 0"));
- }
-
- if (maxDstCStrLength <= 0)
- {
- SetErrorMessageAndBail(("CopyIndexedLineToCStr: Bad parameter, maxDstCStrLength <= 0"));
- }
-
-
- if (gotLastLine != nil)
- {
- *gotLastLine = false;
- }
-
- *theDstCStr = 0;
-
- theCurrentLineOffset = 0;
-
- theCurrentLine = 0;
-
-
- while (theCurrentLine < inWhichLine)
- {
- while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != 0)
- {
- theCurrentLineOffset++;
- }
-
- if (theSrcCStr[theCurrentLineOffset] == 0)
- {
- break;
- }
-
- theCurrentLineOffset++;
- theCurrentLine++;
- }
-
- if (theSrcCStr[theCurrentLineOffset] == 0)
- {
- SetErrorMessageAndLongIntAndBail("CopyIndexedLineToCStr: Too few lines in source text, can't get line ",inWhichLine);
- }
- theEOSOffset = FindCharOffsetInCStr('\r',theSrcCStr + theCurrentLineOffset);
-
- if (theEOSOffset >= 0)
- {
- CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
-
- if (gotLastLine != nil)
- {
- *gotLastLine = false;
- }
-
- if (lineEndIndex != nil)
- {
- *lineEndIndex = theEOSOffset;
- }
- }
-
- else
- {
- theEOSOffset = CStrLength(theSrcCStr + theCurrentLineOffset);
- CopyCSubstrToCStr(theSrcCStr + theCurrentLineOffset,theEOSOffset,theDstCStr,maxDstCStrLength);
-
- if (gotLastLine != nil)
- {
- *gotLastLine = true;
- }
-
- if (lineEndIndex != nil)
- {
- *lineEndIndex = theEOSOffset;
- }
- }
-
- errCode = noErr;
- EXITPOINT:
- return(errCode);
- }
- OSErr CopyIndexedLineToNewHandle(const char *theSrcCStr,int inWhichLine,Handle *outNewHandle)
- {
- OSErr errCode;
- int theCurrentLine;
- int theCurrentLineOffset;
- int byteCount;
- SetErrorMessageAndBailIfNil(theSrcCStr,"CopyIndexedLineToNewHandle: Bad parameter, theSrcCStr == nil");
- SetErrorMessageAndBailIfNil(outNewHandle,"CopyIndexedLineToNewHandle: Bad parameter, outNewHandle == nil");
-
- if (inWhichLine < 0)
- {
- SetErrorMessageAndBail(("CopyIndexedLineToNewHandle: Bad parameter, inWhichLine < 0"));
- }
-
- theCurrentLineOffset = 0;
-
- theCurrentLine = 0;
-
-
- while (theCurrentLine < inWhichLine)
- {
- while (theSrcCStr[theCurrentLineOffset] != '\r' && theSrcCStr[theCurrentLineOffset] != '\0')
- {
- theCurrentLineOffset++;
- }
-
- if (theSrcCStr[theCurrentLineOffset] == '\0')
- {
- break;
- }
-
- theCurrentLineOffset++;
- theCurrentLine++;
- }
-
- if (theSrcCStr[theCurrentLineOffset] == '\0')
- {
- SetErrorMessageAndLongIntAndBail("CopyIndexedLineToNewHandle: Too few lines in source text, can't get line #",inWhichLine);
- }
-
- byteCount = 0;
-
- while (theSrcCStr[theCurrentLineOffset + byteCount] != '\r' && theSrcCStr[theCurrentLineOffset + byteCount] != '\0')
- {
- byteCount++;
- }
-
-
- *outNewHandle = NewHandle(byteCount + 1);
-
- if (*outNewHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("CopyIndexedLineToNewHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
- ::BlockMove(theSrcCStr + theCurrentLineOffset,**outNewHandle,byteCount);
-
- (**outNewHandle)[byteCount] = '\0';
- errCode = noErr;
- EXITPOINT:
- return(errCode);
- }
- OSErr CountDigits(const char *inCStr,int *outNumIntegerDigits,int *outNumFractDigits)
- {
- OSErr errCode = noErr;
- int numIntDigits = 0;
- int numFractDigits = 0;
- int digitIndex = 0;
-
- SetErrorMessageAndBailIfNil(inCStr,"CountDigits: Bad parameter, theSrcCStr == nil");
- SetErrorMessageAndBailIfNil(outNumIntegerDigits,"CountDigits: Bad parameter, outNumIntegerDigits == nil");
- SetErrorMessageAndBailIfNil(outNumFractDigits,"CountDigits: Bad parameter, outNumFractDigits == nil");
-
- digitIndex = 0;
-
- while (inCStr[digitIndex] >= '0' && inCStr[digitIndex] <= '9')
- {
- digitIndex++;
- numIntDigits++;
- }
-
- if (inCStr[digitIndex] == '.')
- {
- digitIndex++;
-
- while (inCStr[digitIndex] >= '0' && inCStr[digitIndex] <= '9')
- {
- digitIndex++;
- numFractDigits++;
- }
- }
-
- *outNumIntegerDigits = numIntDigits;
-
- *outNumFractDigits = numFractDigits;
-
- errCode = noErr;
-
- EXITPOINT:
- return(errCode);
- }
- OSErr ExtractIntFromCStr(const char *theSrcCStr,int *outInt,Boolean skipLeadingSpaces)
- {
- OSErr errCode;
- int theCharIndex;
- if (theSrcCStr == nil)
- {
- SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, theSrcCStr == nil"));
- }
-
- if (outInt == nil)
- {
- SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, outInt == nil"));
- }
-
- *outInt = 0;
-
- theCharIndex = 0;
-
- if (skipLeadingSpaces == true)
- {
- while (theSrcCStr[theCharIndex] == ' ')
- {
- theCharIndex++;
- }
- }
-
- if (theSrcCStr[theCharIndex] < '0' || theSrcCStr[theCharIndex] > '9')
- {
- SetErrorMessageAndBail(("ExtractIntFromCStr: Bad parameter, theSrcCStr contains a bogus numeric representation"));
- }
- while (theSrcCStr[theCharIndex] >= '0' && theSrcCStr[theCharIndex] <= '9')
- {
- *outInt = (*outInt * 10) + (theSrcCStr[theCharIndex] - '0');
-
- theCharIndex++;
- }
-
- errCode = noErr;
- EXITPOINT:
- return(errCode);
- }
- OSErr ExtractIntFromPStr(const unsigned char *theSrcPStr,int *outInt,Boolean skipLeadingSpaces)
- {
- OSErr errCode;
- char theCStr[256];
- if (theSrcPStr == nil)
- {
- SetErrorMessageAndBail(("ExtractIntFromPStr: Bad parameter, theSrcPStr == nil"));
- }
-
- if (outInt == nil)
- {
- SetErrorMessageAndBail(("ExtractIntFromPStr: Bad parameter, outInt == nil"));
- }
-
-
- CopyPStrToCStr(theSrcPStr,theCStr,sizeof(theCStr));
-
-
- errCode = ExtractIntFromCStr(theCStr,outInt,skipLeadingSpaces);
- EXITPOINT:
- return(errCode);
- }
- int CountOccurencesOfCharInCStr(const char inChar,const char *inSrcCStr)
- {
- int theSrcCharIndex;
- int numOccurrences = -1;
- if (inSrcCStr != nil && inChar != '\0')
- {
- numOccurrences = 0;
-
- for (theSrcCharIndex = 0;inSrcCStr[theSrcCharIndex] != '\0';theSrcCharIndex++)
- {
- if (inSrcCStr[theSrcCharIndex] == inChar)
- {
- numOccurrences++;
- }
- }
- }
-
- return(numOccurrences);
- }
- int CountWordsInCStr(const char *inSrcCStr)
- {
- int numWords = -1;
- if (inSrcCStr != nil)
- {
- numWords = 0;
-
- // Skip lead spaces
-
- while (*inSrcCStr == ' ')
- {
- inSrcCStr++;
- }
- while (*inSrcCStr != '\0')
- {
- numWords++;
- while (*inSrcCStr != ' ' && *inSrcCStr != '\0')
- {
- inSrcCStr++;
- }
-
- while (*inSrcCStr == ' ')
- {
- inSrcCStr++;
- }
- }
- }
-
- return(numWords);
- }
- void ConvertCStrToUpperCase(char *theSrcCStr)
- {
- char *theCharPtr;
- if (theSrcCStr != nil)
- {
- theCharPtr = theSrcCStr;
-
- while (*theCharPtr != 0)
- {
- if (*theCharPtr >= 'a' && *theCharPtr <= 'z')
- {
- *theCharPtr = *theCharPtr - 'a' + 'A';
- }
-
- theCharPtr++;
- }
- }
- }
- void ExtractCStrItemFromCStr(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,char *outDstCharPtr,const int inDstCharPtrMaxLength,const Boolean inTreatMultipleDelimsAsSingleDelim)
- {
- int theItem;
- int theSrcCharIndex;
- int theDstCharIndex;
- if (foundItem != nil)
- {
- *foundItem = false;
- }
-
-
- if (outDstCharPtr != nil && inDstCharPtrMaxLength > 0 && inItemNumber >= 0 && inItemDelimiter != 0)
- {
- *outDstCharPtr = 0;
-
- theSrcCharIndex = 0;
-
- for (theItem = 0;theItem < inItemNumber;theItem++)
- {
- while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] != '\0')
- {
- theSrcCharIndex++;
- }
-
- if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
- {
- theSrcCharIndex++;
-
- if (inTreatMultipleDelimsAsSingleDelim)
- {
- while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
- {
- theSrcCharIndex++;
- }
- }
- }
-
-
- if (inSrcCStr[theSrcCharIndex] == '\0')
- {
- goto EXITPOINT;
- }
- }
-
- if (foundItem != nil)
- {
- *foundItem = true;
- }
-
-
- theDstCharIndex = 0;
-
- for (;;)
- {
- if (inSrcCStr[theSrcCharIndex] == 0 || inSrcCStr[theSrcCharIndex] == inItemDelimiter || theDstCharIndex >= inDstCharPtrMaxLength - 1)
- {
- outDstCharPtr[theDstCharIndex] = 0;
-
- break;
- }
-
- outDstCharPtr[theDstCharIndex++] = inSrcCStr[theSrcCharIndex++];
- }
- }
-
-
- EXITPOINT:
- return;
- }
- OSErr ExtractCStrItemFromCStrIntoNewHandle(const char *inSrcCStr,const char inItemDelimiter,const int inItemNumber,Boolean *foundItem,Handle *outNewHandle,const Boolean inTreatMultipleDelimsAsSingleDelim)
- {
- OSErr errCode;
- int theItem;
- int theSrcCharIndex;
- int theItemLength;
- if (inSrcCStr == nil)
- {
- SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inSrcCStr == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (outNewHandle == nil)
- {
- SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, outNewHandle == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (foundItem == nil)
- {
- SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, foundItem == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (inItemNumber < 0)
- {
- SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemNumber < 0");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (inItemDelimiter == 0)
- {
- SetErrorMessage("ExtractCStrItemFromCStrIntoNewHandle: Bad parameter, inItemDelimiter == 0");
- errCode = kGenericError;
- goto EXITPOINT;
- }
- *foundItem = false;
-
- theSrcCharIndex = 0;
-
- for (theItem = 0;theItem < inItemNumber;theItem++)
- {
- while (inSrcCStr[theSrcCharIndex] != inItemDelimiter && inSrcCStr[theSrcCharIndex] != '\0')
- {
- theSrcCharIndex++;
- }
-
- if (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
- {
- theSrcCharIndex++;
-
- if (inTreatMultipleDelimsAsSingleDelim)
- {
- while (inSrcCStr[theSrcCharIndex] == inItemDelimiter)
- {
- theSrcCharIndex++;
- }
- }
- }
-
-
- if (inSrcCStr[theSrcCharIndex] == '\0')
- {
- errCode = noErr;
-
- goto EXITPOINT;
- }
- }
-
- *foundItem = true;
-
-
- for (theItemLength = 0;;theItemLength++)
- {
- if (inSrcCStr[theSrcCharIndex + theItemLength] == 0 || inSrcCStr[theSrcCharIndex + theItemLength] == inItemDelimiter)
- {
- break;
- }
- }
-
- *outNewHandle = NewHandle(theItemLength + 1);
-
- if (*outNewHandle == nil)
- {
- SetErrorMessageAndLongIntAndBail("ExtractCStrItemFromCStrIntoNewHandle: Can't allocate Handle, MemError() = ",MemError());
- }
-
-
- BlockMove(inSrcCStr + theSrcCharIndex,**outNewHandle,theItemLength);
-
- (**outNewHandle)[theItemLength] = 0;
-
- errCode = noErr;
-
-
- EXITPOINT:
- return(errCode);
- }
- OSErr ExtractFloatFromCStr(const char *inCString,extended80 *outFloat)
- {
- OSErr errCode;
- Str255 theStr255;
- Handle theNumberPartsTableHandle = nil;
- long theNumberPartsOffset,theNumberPartsLength;
- FormatResultType theFormatResultType;
- NumberParts theNumberPartsTable;
- NumFormatStringRec theNumFormatStringRec;
- if (inCString == nil)
- {
- SetErrorMessage("ExtractFloatFromCStr: Bad parameter, inCString == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
- if (outFloat == nil)
- {
- SetErrorMessage("ExtractFloatFromCStr: Bad parameter, outFloat == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
-
- // GetIntlResourceTable(smRoman,smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
- GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
-
- if (theNumberPartsTableHandle == nil)
- {
- SetErrorMessage("ExtractFloatFromCStr: Can't get number parts table for converting string representations to/from numeric representations");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (theNumberPartsLength > sizeof(theNumberPartsTable))
- {
- SetErrorMessage("ExtractFloatFromCStr: Number parts table has bad length");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
-
-
- theFormatResultType = (FormatResultType) StringToFormatRec(kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
-
- if (theFormatResultType != fFormatOK)
- {
- SetErrorMessage("ExtractFloatFromCStr: StringToFormatRec() != fFormatOK");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- CopyCStrToPStr(inCString,theStr255,sizeof(theStr255));
- theFormatResultType = (FormatResultType) StringToExtended(theStr255,&theNumFormatStringRec,&theNumberPartsTable,outFloat);
-
- if (theFormatResultType != fFormatOK && theFormatResultType != fBestGuess)
- {
- SetErrorMessageAndLongIntAndBail("ExtractFloatFromCStr: StringToExtended() = ",theFormatResultType);
- }
-
- errCode = noErr;
-
- EXITPOINT:
-
- return(errCode);
- }
- OSErr CopyFloatToCStr(const extended80 *theFloat,char *theCStr,const int maxCStrLength,const int inMaxNumIntDigits,const int inMaxNumFractDigits)
- {
- OSErr errCode;
- Str255 theStr255;
- Handle theNumberPartsTableHandle = nil;
- long theNumberPartsOffset,theNumberPartsLength;
- FormatResultType theFormatResultType;
- NumberParts theNumberPartsTable;
- NumFormatStringRec theNumFormatStringRec;
- if (theCStr == nil)
- {
- SetErrorMessage("CopyFloatToCStr: Bad parameter, theCStr == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
- if (theFloat == nil)
- {
- SetErrorMessage("CopyFloatToCStr: Bad parameter, theFloat == nil");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- // GetIntlResourceTable(smRoman,smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
- GetIntlResourceTable(GetScriptManagerVariable(smSysScript),smNumberPartsTable,&theNumberPartsTableHandle,&theNumberPartsOffset,&theNumberPartsLength);
-
- if (theNumberPartsTableHandle == nil)
- {
- SetErrorMessage("CopyFloatToCStr: Can't get number parts table for converting string representations to/from numeric representations");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- if (theNumberPartsLength > sizeof(theNumberPartsTable))
- {
- SetErrorMessage("CopyFloatToCStr: Number parts table has bad length");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
-
- BlockMove(*theNumberPartsTableHandle + theNumberPartsOffset,&theNumberPartsTable,theNumberPartsLength);
-
-
- if (inMaxNumIntDigits >= 0 || inMaxNumFractDigits >= 0)
- {
- char numberFormat[64];
- int numberFormatLength = 0;
-
- for (int i = 0;i < inMaxNumIntDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
- {
- numberFormat[numberFormatLength++] = '0';
- }
-
- if (inMaxNumFractDigits > 0 && numberFormatLength < sizeof(numberFormat) - 1)
- {
- numberFormat[numberFormatLength++] = '.';
-
- for (int i = 0;i < inMaxNumFractDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
- {
- numberFormat[numberFormatLength++] = '0';
- }
- }
-
- if (numberFormatLength < sizeof(numberFormat) - 1)
- {
- numberFormat[numberFormatLength++] = ';';
- }
-
- if (numberFormatLength < sizeof(numberFormat) - 1)
- {
- numberFormat[numberFormatLength++] = '-';
- }
-
- for (int i = 0;i < inMaxNumIntDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
- {
- numberFormat[numberFormatLength++] = '0';
- }
-
- if (inMaxNumFractDigits > 0 && numberFormatLength < sizeof(numberFormat) - 1)
- {
- numberFormat[numberFormatLength++] = '.';
-
- for (int i = 0;i < inMaxNumFractDigits && numberFormatLength < sizeof(numberFormat) - 1;i++)
- {
- numberFormat[numberFormatLength++] = '0';
- }
- }
-
- numberFormat[numberFormatLength] = '\0';
- Str255 tempStr255;
-
- CopyCStrToPStr(numberFormat,tempStr255,sizeof(tempStr255));
-
- theFormatResultType = (FormatResultType) StringToFormatRec(tempStr255,&theNumberPartsTable,&theNumFormatStringRec);
- }
-
- else
- {
- theFormatResultType = (FormatResultType) StringToFormatRec(kNumberFormatString,&theNumberPartsTable,&theNumFormatStringRec);
- }
-
- if (theFormatResultType != fFormatOK)
- {
- SetErrorMessage("CopyFloatToCStr: StringToFormatRec() != fFormatOK");
- errCode = kGenericError;
- goto EXITPOINT;
- }
- theFormatResultType = (FormatResultType) ExtendedToString(theFloat,&theNumFormatStringRec,&theNumberPartsTable,theStr255);
-
- if (theFormatResultType != fFormatOK)
- {
- SetErrorMessage("CopyFloatToCStr: ExtendedToString() != fFormatOK");
- errCode = kGenericError;
- goto EXITPOINT;
- }
-
- CopyPStrToCStr(theStr255,theCStr,maxCStrLength);
-
- errCode = noErr;
-
- EXITPOINT:
-
- return(errCode);
- }
- void SkipWhiteSpace(char **ioSrcCharPtr,const Boolean inStopAtEOL)
- {
- if (ioSrcCharPtr != nil && *ioSrcCharPtr != nil)
- {
- if (inStopAtEOL)
- {
- while ((**ioSrcCharPtr == ' ' || **ioSrcCharPtr == '\t') && **ioSrcCharPtr != '\r' && **ioSrcCharPtr != '\n')
- {
- *ioSrcCharPtr++;
- }
- }
-
- else
- {
- while (**ioSrcCharPtr == ' ' || **ioSrcCharPtr == '\t')
- {
- *ioSrcCharPtr++;
- }
- }
- }
- }
|