Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
  • Code
  • Branches (204)
  • Releases (207)
    • Branches
    • Releases
    • HEAD
    • refs/heads/OpenSSL-engine-0_9_6-stable
    • refs/heads/OpenSSL-fips-0_9_7-stable
    • refs/heads/OpenSSL-fips-0_9_8-stable
    • refs/heads/OpenSSL-fips-1_2-stable
    • refs/heads/OpenSSL-fips-2_0-dev
    • refs/heads/OpenSSL-fips-2_0-stable
    • refs/heads/OpenSSL-fips2-0_9_7-stable
    • refs/heads/OpenSSL_0_9_6-stable
    • refs/heads/OpenSSL_0_9_7-stable
    • refs/heads/OpenSSL_0_9_8-stable
    • refs/heads/OpenSSL_0_9_8fg-stable
    • refs/heads/OpenSSL_1_0_0-stable
    • refs/heads/OpenSSL_1_0_1-stable
    • refs/heads/OpenSSL_1_0_2-stable
    • refs/heads/OpenSSL_1_1_0-stable
    • refs/heads/OpenSSL_1_1_1-stable
    • refs/heads/SSLeay
    • refs/heads/feature/dtls-1.3
    • refs/heads/feature/ech
    • refs/heads/feature/quic-server
    • refs/heads/master
    • refs/heads/openssl-3.0
    • refs/heads/openssl-3.1
    • refs/heads/openssl-3.2
    • refs/heads/openssl-3.3
    • refs/heads/openssl-3.4
    • refs/heads/tls1.3-draft-18
    • refs/heads/tls1.3-draft-19
    • refs/tags/AFTER_COMPAQ_PATCH
    • refs/tags/BEFORE_COMPAQ_PATCH
    • refs/tags/BEFORE_engine
    • refs/tags/BEN_FIPS_TEST_1
    • refs/tags/BEN_FIPS_TEST_2
    • refs/tags/BEN_FIPS_TEST_3
    • refs/tags/BEN_FIPS_TEST_4
    • refs/tags/BEN_FIPS_TEST_5
    • refs/tags/BEN_FIPS_TEST_6
    • refs/tags/BEN_FIPS_TEST_7
    • refs/tags/BEN_FIPS_TEST_8
    • refs/tags/FIPS_098_TEST_1
    • refs/tags/FIPS_098_TEST_2
    • refs/tags/FIPS_098_TEST_3
    • refs/tags/FIPS_098_TEST_4
    • refs/tags/FIPS_098_TEST_5
    • refs/tags/FIPS_098_TEST_6
    • refs/tags/FIPS_098_TEST_7
    • refs/tags/FIPS_098_TEST_8
    • refs/tags/FIPS_TEST_10
    • refs/tags/FIPS_TEST_9
    • refs/tags/LEVITTE_after_const
    • refs/tags/LEVITTE_before_const
    • refs/tags/OpenSSL-engine-0_9_6
    • refs/tags/OpenSSL-engine-0_9_6-beta1
    • refs/tags/OpenSSL-engine-0_9_6-beta2
    • refs/tags/OpenSSL-engine-0_9_6-beta3
    • refs/tags/OpenSSL-engine-0_9_6a
    • refs/tags/OpenSSL-engine-0_9_6a-beta1
    • refs/tags/OpenSSL-engine-0_9_6a-beta2
    • refs/tags/OpenSSL-engine-0_9_6a-beta3
    • refs/tags/OpenSSL-engine-0_9_6b
    • refs/tags/OpenSSL-engine-0_9_6c
    • refs/tags/OpenSSL-engine-0_9_6d
    • refs/tags/OpenSSL-engine-0_9_6d-beta1
    • refs/tags/OpenSSL-engine-0_9_6e
    • refs/tags/OpenSSL-engine-0_9_6f
    • refs/tags/OpenSSL-engine-0_9_6g
    • refs/tags/OpenSSL-engine-0_9_6h
    • refs/tags/OpenSSL-engine-0_9_6i
    • refs/tags/OpenSSL-engine-0_9_6j
    • refs/tags/OpenSSL-engine-0_9_6k
    • refs/tags/OpenSSL-engine-0_9_6l
    • refs/tags/OpenSSL-engine-0_9_6m
    • refs/tags/OpenSSL-fips-1_2_0
    • refs/tags/OpenSSL-fips-1_2_1
    • refs/tags/OpenSSL-fips-1_2_2
    • refs/tags/OpenSSL-fips-1_2_3
    • refs/tags/OpenSSL-fips-2_0
    • refs/tags/OpenSSL-fips-2_0-pl1
    • refs/tags/OpenSSL-fips-2_0-rc1
    • refs/tags/OpenSSL-fips-2_0-rc2
    • refs/tags/OpenSSL-fips-2_0-rc3
    • refs/tags/OpenSSL-fips-2_0-rc4
    • refs/tags/OpenSSL-fips-2_0-rc5
    • refs/tags/OpenSSL-fips-2_0-rc6
    • refs/tags/OpenSSL-fips-2_0-rc7
    • refs/tags/OpenSSL-fips-2_0-rc8
    • refs/tags/OpenSSL-fips-2_0-rc9
    • refs/tags/OpenSSL-fips-2_0_1
    • refs/tags/OpenSSL_0_9_1c
    • refs/tags/OpenSSL_0_9_2b
    • refs/tags/OpenSSL_0_9_3
    • refs/tags/OpenSSL_0_9_3a
    • refs/tags/OpenSSL_0_9_3beta1
    • refs/tags/OpenSSL_0_9_3beta2
    • refs/tags/OpenSSL_0_9_4
    • refs/tags/OpenSSL_0_9_5
    • refs/tags/OpenSSL_0_9_5a
    • refs/tags/OpenSSL_0_9_5a-beta1
    • refs/tags/OpenSSL_0_9_5a-beta2
    • refs/tags/OpenSSL_0_9_5beta1
    • refs/tags/OpenSSL_0_9_5beta2
    • refs/tags/OpenSSL_0_9_6
    • refs/tags/OpenSSL_0_9_6-beta1
    • refs/tags/OpenSSL_0_9_6-beta2
    • refs/tags/OpenSSL_0_9_6-beta3
    • refs/tags/OpenSSL_0_9_6a
    • refs/tags/OpenSSL_0_9_6a-beta1
    • refs/tags/OpenSSL_0_9_6a-beta2
    • refs/tags/OpenSSL_0_9_6a-beta3
    • refs/tags/OpenSSL_0_9_6b
    • refs/tags/OpenSSL_0_9_6c
    • refs/tags/OpenSSL_0_9_6d
    • refs/tags/OpenSSL_0_9_6d-beta1
    • refs/tags/OpenSSL_0_9_6e
    • refs/tags/OpenSSL_0_9_6f
    • refs/tags/OpenSSL_0_9_6g
    • refs/tags/OpenSSL_0_9_6h
    • refs/tags/OpenSSL_0_9_6i
    • refs/tags/OpenSSL_0_9_6j
    • refs/tags/OpenSSL_0_9_6k
    • refs/tags/OpenSSL_0_9_6l
    • refs/tags/OpenSSL_0_9_6m
    • refs/tags/OpenSSL_0_9_7
    • refs/tags/OpenSSL_0_9_7-beta1
    • refs/tags/OpenSSL_0_9_7-beta2
    • refs/tags/OpenSSL_0_9_7-beta3
    • refs/tags/OpenSSL_0_9_7-beta4
    • refs/tags/OpenSSL_0_9_7-beta5
    • refs/tags/OpenSSL_0_9_7-beta6
    • refs/tags/OpenSSL_0_9_7a
    • refs/tags/OpenSSL_0_9_7b
    • refs/tags/OpenSSL_0_9_7c
    • refs/tags/OpenSSL_0_9_7d
    • refs/tags/OpenSSL_0_9_7e
    • refs/tags/OpenSSL_0_9_7f
    • refs/tags/OpenSSL_0_9_7g
    • refs/tags/OpenSSL_0_9_7h
    • refs/tags/OpenSSL_0_9_7i
    • refs/tags/OpenSSL_0_9_7j
    • refs/tags/OpenSSL_0_9_7k
    • refs/tags/OpenSSL_0_9_7l
    • refs/tags/OpenSSL_0_9_7m
    • refs/tags/OpenSSL_0_9_8
    • refs/tags/OpenSSL_0_9_8-beta1
    • refs/tags/OpenSSL_0_9_8-beta2
    • refs/tags/OpenSSL_0_9_8-beta3
    • refs/tags/OpenSSL_0_9_8-beta4
    • refs/tags/OpenSSL_0_9_8-beta5
    • refs/tags/OpenSSL_0_9_8-beta6
    • refs/tags/OpenSSL_0_9_8a
    • refs/tags/OpenSSL_0_9_8b
    • refs/tags/OpenSSL_0_9_8c
    • refs/tags/OpenSSL_0_9_8d
    • refs/tags/OpenSSL_0_9_8e
    • refs/tags/OpenSSL_0_9_8f
    • refs/tags/OpenSSL_0_9_8g
    • refs/tags/OpenSSL_0_9_8h
    • refs/tags/OpenSSL_0_9_8i
    • refs/tags/OpenSSL_0_9_8j
    • refs/tags/OpenSSL_0_9_8k
    • refs/tags/OpenSSL_0_9_8l
    • refs/tags/OpenSSL_0_9_8m
    • refs/tags/OpenSSL_0_9_8m-beta1
    • refs/tags/OpenSSL_0_9_8n
    • refs/tags/OpenSSL_0_9_8o
    • refs/tags/OpenSSL_0_9_8p
    • refs/tags/OpenSSL_0_9_8q
    • refs/tags/OpenSSL_0_9_8r
    • refs/tags/OpenSSL_0_9_8s
    • refs/tags/OpenSSL_0_9_8t
    • refs/tags/OpenSSL_0_9_8u
    • refs/tags/OpenSSL_0_9_8v
    • refs/tags/OpenSSL_0_9_8w
    • refs/tags/OpenSSL_0_9_8x
    • refs/tags/OpenSSL_1_0_0
    • refs/tags/OpenSSL_1_0_0-beta1
    • refs/tags/OpenSSL_1_0_0-beta2
    • refs/tags/OpenSSL_1_0_0-beta3
    • refs/tags/OpenSSL_1_0_0-beta4
    • refs/tags/OpenSSL_1_0_0-beta5
    • refs/tags/OpenSSL_1_0_0a
    • refs/tags/OpenSSL_1_0_0b
    • refs/tags/OpenSSL_1_0_0c
    • refs/tags/OpenSSL_1_0_0d
    • refs/tags/OpenSSL_1_0_0e
    • refs/tags/OpenSSL_1_0_0f
    • refs/tags/OpenSSL_1_0_0g
    • refs/tags/OpenSSL_1_0_0h
    • refs/tags/OpenSSL_1_0_0i
    • refs/tags/OpenSSL_1_0_0j
    • refs/tags/OpenSSL_1_0_1
    • refs/tags/OpenSSL_1_0_1-beta1
    • refs/tags/OpenSSL_1_0_1-beta2
    • refs/tags/OpenSSL_1_0_1-beta3
    • refs/tags/OpenSSL_1_0_1a
    • refs/tags/OpenSSL_1_0_1b
    • refs/tags/OpenSSL_1_0_1c
    • refs/tags/OpenSSL_FIPS_1_0
    • refs/tags/SSLeay_0_8_1b
    • refs/tags/SSLeay_0_9_0b
    • refs/tags/SSLeay_0_9_1b
    • refs/tags/STATE_after_zlib
    • refs/tags/STATE_before_zlib
    • refs/tags/rsaref
    • openssl-3.4.0-alpha1
    • openssl-3.3.2
    • openssl-3.3.1
    • openssl-3.3.0-beta1
    • openssl-3.3.0-alpha1
    • openssl-3.3.0
    • openssl-3.2.3
    • openssl-3.2.2
    • openssl-3.2.1
    • openssl-3.2.0-beta1
    • openssl-3.2.0-alpha2
    • openssl-3.2.0-alpha1
    • openssl-3.2.0
    • openssl-3.1.7
    • openssl-3.1.6
    • openssl-3.1.5
    • openssl-3.1.4
    • openssl-3.1.3
    • openssl-3.1.2
    • openssl-3.1.1
    • openssl-3.1.0-beta1
    • openssl-3.1.0-alpha1
    • openssl-3.1.0
    • openssl-3.0.9
    • openssl-3.0.8
    • openssl-3.0.7
    • openssl-3.0.6
    • openssl-3.0.5
    • openssl-3.0.4
    • openssl-3.0.3
    • openssl-3.0.2
    • openssl-3.0.15
    • openssl-3.0.14
    • openssl-3.0.13
    • openssl-3.0.12
    • openssl-3.0.11
    • openssl-3.0.10
    • openssl-3.0.1
    • openssl-3.0.0-beta2
    • openssl-3.0.0-beta1
    • openssl-3.0.0-alpha9
    • openssl-3.0.0-alpha8
    • openssl-3.0.0-alpha7
    • openssl-3.0.0-alpha6
    • openssl-3.0.0-alpha5
    • openssl-3.0.0-alpha4
    • openssl-3.0.0-alpha3
    • openssl-3.0.0-alpha2
    • openssl-3.0.0-alpha17
    • openssl-3.0.0-alpha16
    • openssl-3.0.0-alpha15
    • openssl-3.0.0-alpha14
    • openssl-3.0.0-alpha13
    • openssl-3.0.0-alpha12
    • openssl-3.0.0-alpha11
    • openssl-3.0.0-alpha10
    • openssl-3.0.0-alpha1
    • openssl-3.0.0
    • master-pre-reformat
    • master-pre-auto-reformat
    • master-post-reformat
    • master-post-auto-reformat
    • OpenSSL_1_1_1w
    • OpenSSL_1_1_1v
    • OpenSSL_1_1_1u
    • OpenSSL_1_1_1t
    • OpenSSL_1_1_1s
    • OpenSSL_1_1_1r
    • OpenSSL_1_1_1q
    • OpenSSL_1_1_1p
    • OpenSSL_1_1_1o
    • OpenSSL_1_1_1n
    • OpenSSL_1_1_1m
    • OpenSSL_1_1_1l
    • OpenSSL_1_1_1k
    • OpenSSL_1_1_1j
    • OpenSSL_1_1_1i
    • OpenSSL_1_1_1h
    • OpenSSL_1_1_1g
    • OpenSSL_1_1_1f
    • OpenSSL_1_1_1e
    • OpenSSL_1_1_1d
    • OpenSSL_1_1_1c
    • OpenSSL_1_1_1b
    • OpenSSL_1_1_1a
    • OpenSSL_1_1_1-pre9
    • OpenSSL_1_1_1-pre8
    • OpenSSL_1_1_1-pre7
    • OpenSSL_1_1_1-pre6
    • OpenSSL_1_1_1-pre5
    • OpenSSL_1_1_1-pre4
    • OpenSSL_1_1_1-pre3
    • OpenSSL_1_1_1-pre2
    • OpenSSL_1_1_1-pre1
    • OpenSSL_1_1_1
    • OpenSSL_1_1_0l
    • OpenSSL_1_1_0k
    • OpenSSL_1_1_0j
    • OpenSSL_1_1_0i
    • OpenSSL_1_1_0h
    • OpenSSL_1_1_0g
    • OpenSSL_1_1_0f
    • OpenSSL_1_1_0e
    • OpenSSL_1_1_0d
    • OpenSSL_1_1_0c
    • OpenSSL_1_1_0b
    • OpenSSL_1_1_0a
    • OpenSSL_1_1_0-pre6
    • OpenSSL_1_1_0-pre5
    • OpenSSL_1_1_0-pre4
    • OpenSSL_1_1_0-pre3
    • OpenSSL_1_1_0-pre2
    • OpenSSL_1_1_0-pre1
    • OpenSSL_1_1_0
    • OpenSSL_1_0_2u
    • OpenSSL_1_0_2t
    • OpenSSL_1_0_2s
    • OpenSSL_1_0_2r
    • OpenSSL_1_0_2q
    • OpenSSL_1_0_2p
    • OpenSSL_1_0_2o
    • OpenSSL_1_0_2n
    • OpenSSL_1_0_2m
    • OpenSSL_1_0_2l
    • OpenSSL_1_0_2k
    • OpenSSL_1_0_2j
    • OpenSSL_1_0_2i
    • OpenSSL_1_0_2h
    • OpenSSL_1_0_2g
    • OpenSSL_1_0_2f
    • OpenSSL_1_0_2e
    • OpenSSL_1_0_2d
    • OpenSSL_1_0_2c
    • OpenSSL_1_0_2b
    • OpenSSL_1_0_2a
    • OpenSSL_1_0_2-pre-reformat
    • OpenSSL_1_0_2-pre-auto-reformat
    • OpenSSL_1_0_2-post-reformat
    • OpenSSL_1_0_2-post-auto-reformat
    • OpenSSL_1_0_2-beta3
    • OpenSSL_1_0_2-beta2
    • OpenSSL_1_0_2-beta1
    • OpenSSL_1_0_2
    • OpenSSL_1_0_1u
    • OpenSSL_1_0_1t
    • OpenSSL_1_0_1s
    • OpenSSL_1_0_1r
    • OpenSSL_1_0_1q
    • OpenSSL_1_0_1p
    • OpenSSL_1_0_1o
    • OpenSSL_1_0_1n
    • OpenSSL_1_0_1m
    • OpenSSL_1_0_1l
    • OpenSSL_1_0_1k
    • OpenSSL_1_0_1j
    • OpenSSL_1_0_1i
    • OpenSSL_1_0_1h
    • OpenSSL_1_0_1g
    • OpenSSL_1_0_1f
    • OpenSSL_1_0_1e
    • OpenSSL_1_0_1d
    • OpenSSL_1_0_1-pre-reformat
    • OpenSSL_1_0_1-pre-auto-reformat
    • OpenSSL_1_0_1-post-reformat
    • OpenSSL_1_0_1-post-auto-reformat
    • OpenSSL_1_0_0t
    • OpenSSL_1_0_0s
    • OpenSSL_1_0_0r
    • OpenSSL_1_0_0q
    • OpenSSL_1_0_0p
    • OpenSSL_1_0_0o
    • OpenSSL_1_0_0n
    • OpenSSL_1_0_0m
    • OpenSSL_1_0_0l
    • OpenSSL_1_0_0k
    • OpenSSL_1_0_0-pre-reformat
    • OpenSSL_1_0_0-pre-auto-reformat
    • OpenSSL_1_0_0-post-reformat
    • OpenSSL_1_0_0-post-auto-reformat
    • OpenSSL_0_9_8zh
    • OpenSSL_0_9_8zg
    • OpenSSL_0_9_8zf
    • OpenSSL_0_9_8ze
    • OpenSSL_0_9_8zd
    • OpenSSL_0_9_8zc
    • OpenSSL_0_9_8zb
    • OpenSSL_0_9_8za
    • OpenSSL_0_9_8y
    • OpenSSL_0_9_8-pre-reformat
    • OpenSSL_0_9_8-pre-auto-reformat
    • OpenSSL_0_9_8-post-reformat
    • OpenSSL_0_9_8-post-auto-reformat
    • OpenSSL-fips-2_0_9
    • OpenSSL-fips-2_0_8
    • OpenSSL-fips-2_0_7
    • OpenSSL-fips-2_0_6
    • OpenSSL-fips-2_0_5
    • OpenSSL-fips-2_0_4
    • OpenSSL-fips-2_0_3
    • OpenSSL-fips-2_0_2
    • OpenSSL-fips-2_0_16
    • OpenSSL-fips-2_0_15
    • OpenSSL-fips-2_0_14
    • OpenSSL-fips-2_0_13
    • OpenSSL-fips-2_0_12
    • OpenSSL-fips-2_0_11
    • OpenSSL-fips-2_0_10
  • 2b77684
  • /
  • MacOS
  • /
  • GetHTTPS.src
  • /
  • CPStringUtils.cpp
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
  • release
content badge Iframe embedding
swh:1:cnt:617aae2c70680da3069675f3e1122cd69522a4b4
directory badge Iframe embedding
swh:1:dir:a39b9a695ffa7715b55a504510fd4425d56ee869
revision badge
swh:1:rev:e71ebf275da66dfd601c92e0e80a35114c32f6f8
snapshot badge
swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
release badge
swh:1:rel:4ec29ae59fd474a8f9037e08e8219b99dc608e2d
Tip revision: e71ebf275da66dfd601c92e0e80a35114c32f6f8 authored by Matt Caswell on 14 August 2018, 13:01:02 UTC
Prepare for 1.0.2p release
Tip revision: e71ebf2
CPStringUtils.cpp
/* ====================================================================
 * 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++;
			}
		}
	}
}

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top