Convert Class Reference

This class is used to convert things from one form to another. Mainly contains static functions. Started life as a series of conversion functions before being made to see the light and profess the one and only true class. At present in the Winoil class as it needs converting to TCHARs and using the MFC forms of scanf and sprintf .. More...

#include <convert.h>

List of all members.

Public Types

typedef BOOL(* PFNSTRINGTOINT32 )(const StringBase &, INT32 *)
typedef BOOL(* PFNSTRINGTODOUBLE )(const StringBase &, double *)

Static Public Member Functions

static BOOL Init ()
 AppPrefsDlg Init method. Called when the kernel initialises. It reads from the Windows ini file the settings for things like the current decimal point character, thousands separator and number of decimal places and stores these for later use.
static BOOL GetCurrentNumberFormat ()
 Read from the operating system what the user has defined to be their decimal point character and thousands separator character and store these in the class variables. It is now also called from the mainframe message handler, when it receives a WM_WININICHANGE message.
static char GetDecimalPointChar ()
 To find out what the current decimal point character is.
static char GetThousandsSepChar ()
 To find out what the current thousands separator character is.
static UINT32 GetNumberDecimalPlaces ()
 To find out what the current number of decimal places is.
static BOOL SetDecimalPointChar (char NewDecimalPoint)
 Allows the setting up of the character to separate whole part of number from the fractional part in displayed numbers e.g. 56.79 This is read from the OS at present. This function just provided just in case we wish to overide this in the future.
static BOOL SetThousandsSepChar (char NewThousandsSep)
 Allows the setting up of the character to be used to separate thousands in displayed numbers e.g. 10,000. This is read from the OS at present. This function just provided just in case we wish to overide this in the future.
static BOOL SetNumberDecimalPlaces (UINT32 NewDPs)
 Allows the setting up of the number of decimal places to display to by default This is read from the OS at present. This function just provided just in case we wish to overide this in the future.
static MILLIPOINT StringToMillipoints (const StringBase &, UnitType, BOOL *)
 Convert the string into a MILLIPOINT representation of the number of millipoints. eg '1in' would be converted to 72000 millipoints. Does NOT cope with '0.25in0.75in' - this would return 18000 millipoints instead of 72000 millipoints.
static void NumberToString (MILLIPOINT Number, StringBase *MyString)
 Appends the string representation of the given number to the end of MyString.
static BOOL MillipointsToString (double, UnitType, StringBase *, INT32 DecimalPlaces=-1)
 Convert a number in MpValue to a string representation of that number in the given units. ie converting 72000 millipoints to inches would give the string '1in'. If DecimalPlaces = -1 then use the default preference value which the user has specified. See Also: DocUnitList.
static double StringToDouble (const StringBase &, UnitType, BOOL *)
 Convert the string into a floating point representation of the number of millipoints. eg '1in' would be converted to 72000.0 millipoints. Does NOT cope with '0.25in0.75in' - this would return 18000.0 millipoints instead of 72000.0 millipoints. If you want a MILLIPOINT value, use StringToMillipoint to ensure correct rounding.
static BOOL StringToDouble (const StringBase &InputString, double *Number)
 Converts a string into its double equivalent.
static BOOL DoubleToString (double Number, StringBase *OutputString, INT32 DecimalPlaces=-1)
 Converts a double to a its string equivalent.
static BOOL StringToComponents (const StringBase &InputString, double *pValue, UnitType *pUnits)
 General purpose routine for extracting the value and unit components of a string. E.g.1 the string "42.6in" would extract the value 42.6 and the unit type INCHES E.g.2 The string "42.6" would give *pValue=42.6,*pUnits=NOTYPE, and TRUE is returned. E.g.3 "4in5in" gives *pValue=9,*pUnits=INCHES, and returns TRUE E.g.4 "1in2cm" gives *pValue = 1.79,*pUnits=INCHES, and returns TRUE In this case it takes the first unit specified as the dominant unit (INCHES in this case), so the result is 1in plus 2cm converted to INCHES which is about 0.79in.
static double ConvertToNewUnits (double Value, UnitType Units, UnitType NewUnits)
 Used convert one value into an equivalent value in another unit base E.g. ConvertToNewUnits(3,CENTIMETRES,MILLIMETRES) would return 30.0 because 3cm == 30mm.
static BOOL ConvertDoubleToMillipoint (double Value, MILLIPOINT *pResult)
 Converts a double to a MILLIPOINT, checking first whether such a conversion is possible. It returns FALSE if Value is beyond the limits of a signed 32 bit integer.
static void ConvertMillipointToDouble (MILLIPOINT Value, double *pResult)
 Converts a MILLIPOINT to a double. At the moment, this function just does a simple cast. I've only put it in because I did the sister function ConvertDoubleToMillipoint.
static BOOL LongToString (INT32 Number, StringBase *OutputString)
 Converts a INT32 to a its string equivalent.
static BOOL StringToLong (const StringBase &InputString, INT32 *Number)
 Converts a string into its INT32 equivalent.
static UINT32 StringToBytes (const StringBase &pString, BOOL *Valid)
 Takes a string with a textual description of an amount of memory, and returns the amount of bytes described by the string.
static BOOL BytesToString (StringBase *pString, UINT32 Bytes)
 Converts the Bytes number into a string of the following format: Bytes = 0 "0 bytes" Bytes = 1 "1 byte" 2 <= Bytes < 4096 "<n> bytes" 4096 <= Bytes < 4M "<n/1024> K" 4M <= Bytes "<n/1Meg> M".
static BOOL ReplaceDecimalPoint (StringBase *pString)
 Searches the specified string for a decimal point and replaces this with the specified DecimalPoint character. It assumes that a check has been made already to see if we are using a non-decimal point character and so this routine is only called when the replacement is actually required. This MUST ALWAYS be after the StripTrailingZeros code. Otherwise, the StripTrailingZeros code would have to search for two items, a decimal point and the international form of the decimal point.
static BOOL StripTrailingZeros (StringBase *pString)
 Strip trailing zeros (& decimal point) from a string containing a decimal number This MUST ALWAYS be called before the replace decimal point character code. Otherwise, we would have to search for two items, a decimal point and the international form of the decimal point.
static BOOL IsCharUnitType (TCHAR Char)
 Checks to see if this char could be part of a string that specifies a unit We have to allow most chars so that arbitrary units can be defined like such as pounds, dollars or percentages Illegal unit specifier chars are :- ASCII value <= ' ' Numericals - '1', '2', etc Minus sign - '-' Decimal point - '.' Thousand separator - ',' as in "10,000".
static BOOL IsCharStartOfNumber (TCHAR Char)
 Checks to see if this char could be the first char in a string that specifies a number Legal number-starting chars are :- Numericals - '1', '2', etc Minus sign - '-' Decimal point - '.'.
static BOOL ReadUnitType (const StringBase &Str, INT32 *pPos, UnitType *pUnitType)
 General purpose routine for extracting the unit type from a string E.g. "42cm45mm" with *pPos = 2 returns TRUE with *pUnitType == CENTIMETRES & *pPos == 4 "42cm45mm" with *pPos = 6 returns TRUE with *pUnitType == MILLIMETRES & *pPos == 8.
static BOOL ReadNumber (const StringBase &Str, INT32 *pPos, double *pResult)
 General purpose routine for extracting the number from a string E.g. "42cm45.7mm" with *pPos == 0 returns TRUE with *pResult and 42.0 & *pPos == 2 "42cm-45.7mm" with *pPos == 4 returns TRUE with *pResult and -45.7 & *pPos == 9.

Static Protected Attributes

static char DecimalPoint = '.'
static char ThousandSep = ','
static char MinusSign = '-'
static UINT32 NumDecimalPlaces = 2


Detailed Description

This class is used to convert things from one form to another. Mainly contains static functions. Started life as a series of conversion functions before being made to see the light and profess the one and only true class. At present in the Winoil class as it needs converting to TCHARs and using the MFC forms of scanf and sprintf ..

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Note by Rik who did the original functions 11/5/93:-

These functions will provide a means of converting from Doc Coords (millipoints) to Strings and visa versa. For example, convert 72000 millipoints to the string 1in or 72pt as well as converting from the string '1in72pt' to 144000 millipoints. The units to convert to can be chosen, as can the number of decimal points. When converting from string back to millipoints, all the valid units are added together. If an error is detected (ie '4cm72zx' ), then everything up to the error will be used (4cm).

See also:
DimScale, Spread, Layer

Definition at line 141 of file convert.h.


Member Typedef Documentation

typedef BOOL(* Convert::PFNSTRINGTODOUBLE)(const StringBase &, double *)
 

Definition at line 196 of file convert.h.

typedef BOOL(* Convert::PFNSTRINGTOINT32)(const StringBase &, INT32 *)
 

Definition at line 195 of file convert.h.


Member Function Documentation

BOOL Convert::BytesToString StringBase pString,
UINT32  Bytes
[static]
 

Converts the Bytes number into a string of the following format: Bytes = 0 "0 bytes" Bytes = 1 "1 byte" 2 <= Bytes < 4096 "<n> bytes" 4096 <= Bytes < 4M "<n/1024> K" 4M <= Bytes "<n/1Meg> M".

Author:
Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
Date:
26th August 1994
Parameters:
String - The string to store the formatted memory size in. The [INPUTS] existing contents of the string are overwritten. Bytes - The number of bytes which to format and store.
Returns:
-

Definition at line 1368 of file convert.cpp.

01369 {
01370     ERROR2IF(pString==NULL, FALSE, "NULL output pointer");
01371     ERROR3IF(Bytes<0, "The number of bytes must be positive");
01372     if(Bytes<0) Bytes = 0-Bytes;
01373     pString->Empty();
01374     
01375     INT32 Number = 0;
01376     UINT32 Resource = 0;    
01377     String_16 Working;
01378     String_8 ThousandsSepStr;
01379     ThousandsSepStr += (TCHAR)ThousandSep;
01380 
01381 
01382     // Work out which resource string to use depending on the number of bytes
01383     if (Bytes == 1)
01384     {
01385         Number = 1;
01386         Resource = _R(IDS_MEMORYFORMAT_BYTE);
01387     }
01388     else
01389     {
01390         if (Bytes < 4096)
01391         {
01392             Number = Bytes;
01393             Resource = _R(IDS_MEMORYFORMAT_BYTES);
01394         }
01395         else
01396         {
01397             if (Bytes < (4096*1024))
01398             {
01399                 Number = Bytes/1024;
01400                 Resource = _R(IDS_MEMORYFORMAT_KILO);
01401             }
01402             else
01403             {
01404                 Number = Bytes/(1024*1024);
01405                 Resource = _R(IDS_MEMORYFORMAT_MEGA);
01406             }
01407         }
01408     }
01409 
01410     // Put the number into a string and add thousand seperator
01411     Working._MakeMsg( wxT("#1%lu"), Number ); 
01412     if (Working.Length() > 3)
01413         Working.Insert(ThousandsSepStr, Working.Length()-3);
01414     
01415     // put the number string into the string resource   
01416     pString->MakeMsg(Resource, &Working);
01417 
01418     return TRUE;
01419 }

BOOL Convert::ConvertDoubleToMillipoint double  Value,
MILLIPOINT pResult
[static]
 

Converts a double to a MILLIPOINT, checking first whether such a conversion is possible. It returns FALSE if Value is beyond the limits of a signed 32 bit integer.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/7/94
Parameters:
Value = the fp value to convert [INPUTS]
pResult = the MILLIPOINT var to place the result in [OUTPUTS]
Returns:
TRUE if the conversion was OK FALSE if the conversion caused an overflow error
See also:
ConvertMillipointToDouble

Definition at line 1228 of file convert.cpp.

01229 {
01230     Value += 0.5;   // Round up the value
01231 
01232     if ((Value < MIN_MILLIPOINT_VAL) || (Value > MAX_MILLIPOINT_VAL))
01233         return FALSE;
01234 
01235     *pResult = (MILLIPOINT)Value;
01236     return TRUE;
01237 }

void Convert::ConvertMillipointToDouble MILLIPOINT  Value,
double *  pResult
[static]
 

Converts a MILLIPOINT to a double. At the moment, this function just does a simple cast. I've only put it in because I did the sister function ConvertDoubleToMillipoint.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
6/7/94
Parameters:
Value = the MILLIPOINT value to convert [INPUTS]
pResult = the double var to place the result in [OUTPUTS]
Returns:
-
See also:
ConvertDoubleToMillipoint

Definition at line 1255 of file convert.cpp.

01256 {
01257     *pResult = (double)Value;
01258 }

double Convert::ConvertToNewUnits double  Value,
UnitType  OldUnits,
UnitType  NewUnits
[static]
 

Used convert one value into an equivalent value in another unit base E.g. ConvertToNewUnits(3,CENTIMETRES,MILLIMETRES) would return 30.0 because 3cm == 30mm.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/94
Parameters:
Value - value to convert [INPUTS] OldUnits- units Value is defined in NewUnits- the units you want Value to be converted toTYPE
- [OUTPUTS]
Returns:
The new value

Definition at line 687 of file convert.cpp.

00688 {
00689     ENSURE(NewUnits != NOTYPE,"Can't convert to NOTYPE units");
00690 
00691     DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
00692     Unit* pNewUnit = pDocUnitList->FindUnit(NewUnits);
00693     double NumMillipoints = 1.0;
00694 
00695     if (OldUnits != NOTYPE)
00696     {
00697         Unit* pOldUnit = pDocUnitList->FindUnit(OldUnits);
00698         NumMillipoints = Value * pOldUnit->GetMillipoints();
00699     }
00700     else
00701         NumMillipoints = Value;
00702 
00703     return (NumMillipoints / pNewUnit->GetMillipoints());
00704 }

BOOL Convert::DoubleToString double  Number,
StringBase OutputString,
INT32  DecimalPlaces = -1
[static]
 

Converts a double to a its string equivalent.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/12/94
Parameters:
Number - The number you want turning into a string [INPUTS] DecimalPlaces - The number of Decimal places required (0-3). This defaults to -1 which means use the default preference value. Don't override it unless absolutely necessary.
OutputString - The string that gets created [OUTPUTS]
Returns:
TRUE if the conversion worked, false otherwise
See also:
StringToDouble
This routine is a bit of a bodge

Definition at line 1089 of file convert.cpp.

01090 {
01091     // Generate the output string in a simple char array
01092     TCHAR dpformat[32]; 
01093     TCHAR TempString[32];
01094 
01095     // Use the default/preference or desired number of decimal places
01096     if (DecimalPlaces < 0)
01097         DecimalPlaces = (INT32) NumDecimalPlaces;       // Use the preference value
01098 
01099     camSnprintf( dpformat, 32, _T("%%.%df"), (INT32) DecimalPlaces);        // make %.xf formatting string
01100     camSnprintf( TempString, 32, dpformat, (double)Number );                    // uses FP
01101 
01102     *OutputString = TempString;     // Copy the resulting string into the String
01103     
01104     // Look for all zeros after decimal point and if so then remove
01105     StripTrailingZeros(OutputString);
01106 
01107     // Extra bodge required so that if the user has specified display values using
01108     // a non full stop to show decimal points then we must replace the point that
01109     // is present by the specified character.
01110     if (DecimalPoint != '.')
01111     {
01112         ReplaceDecimalPoint(OutputString);
01113     }
01114     return TRUE;
01115 }

BOOL Convert::GetCurrentNumberFormat  )  [static]
 

Read from the operating system what the user has defined to be their decimal point character and thousands separator character and store these in the class variables. It is now also called from the mainframe message handler, when it receives a WM_WININICHANGE message.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
CMainFrame::OnWinIniChange()

Definition at line 198 of file convert.cpp.

00199 {
00200     String_8    ThousandsSepStr( _T(",") ); 
00201     String_8    DecimalPointStr( _T(".") ); 
00202     NumDecimalPlaces = 2;
00203 
00204     // Read from the operating system what the user has defined to be their decimal point
00205     // character and thousands separator character.
00206     LocalEnvironment::GetThousandsSeparator(&ThousandsSepStr);
00207     LocalEnvironment::GetDecimalPointChar(&DecimalPointStr);
00208     LocalEnvironment::GetNumberOfDecimalPlaces(&NumDecimalPlaces);
00209     
00210     // Set up the static char variables to reflect these
00211     ThousandSep = ((TCHAR *) ThousandsSepStr)[0];
00212     DecimalPoint = ((TCHAR *) DecimalPointStr)[0];
00213 
00214     // Check for "testing" of internationalisation.
00215     ERROR3IF(ThousandSep == DecimalPoint,
00216                 "Convert::GetCurrentNumberFormat: decimal point and "
00217                 "thousands separator are the same");
00218 
00219 //char to TCHAR for DBCS
00220 TRACEUSER( "Neville", wxT("InitConvert() ThousandsSepStr=%s\n"), (TCHAR *)ThousandsSepStr );
00221 TRACEUSER( "Neville", wxT("InitConvert() DecimalPointStr=%s\n"), (TCHAR *)DecimalPointStr );
00222 TRACEUSER( "Neville", wxT("InitConvert() NumDecimalPlaces=%d\n"), NumDecimalPlaces );
00223 
00224     return TRUE;
00225 }

char Convert::GetDecimalPointChar  )  [static]
 

To find out what the current decimal point character is.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The current decimal point character being used.
See also:
SetDecimalPointChar(); GetCurrentNumberFormat();

Definition at line 242 of file convert.cpp.

00243 {
00244     return DecimalPoint;
00245 }

UINT32 Convert::GetNumberDecimalPlaces  )  [static]
 

To find out what the current number of decimal places is.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The current number of decimal places being used.
See also:
SetNumberDecimalPlaces();

Definition at line 281 of file convert.cpp.

00282 {
00283     return NumDecimalPlaces;
00284 }

char Convert::GetThousandsSepChar  )  [static]
 

To find out what the current thousands separator character is.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The current thousands separator character being used.
See also:
SetThousandsSepChar(); GetCurrentNumberFormat();

Definition at line 261 of file convert.cpp.

00262 {
00263     return ThousandSep;
00264 }

BOOL Convert::Init void   )  [static]
 

AppPrefsDlg Init method. Called when the kernel initialises. It reads from the Windows ini file the settings for things like the current decimal point character, thousands separator and number of decimal places and stores these for later use.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/1/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
See also:
GetCurrentNumberFormat();

Definition at line 163 of file convert.cpp.

00164 {
00165 
00166 //  // Declare any preferences that we require.
00167 //  if ( Camelot.DeclareSection(TEXT("Preferences"), 3) )
00168 //  {
00169 //      // section declared ok so now define the preference option  
00170 //      Camelot.DeclarePref(TEXT("Preferences"), TEXT("DecimalPointChar"), &DecimalPoint, 0, 255);
00171 //      Camelot.DeclarePref(TEXT("Preferences"), TEXT("ThousandSepChar"), &ThousandSep, 0, 255);
00172 //  }
00173 
00174     // Get the current details from the OS about the number format specified by the user
00175     // If fails then return this to the caller.
00176     return GetCurrentNumberFormat();
00177 }

BOOL Convert::IsCharStartOfNumber TCHAR  Char  )  [static]
 

Checks to see if this char could be the first char in a string that specifies a number Legal number-starting chars are :- Numericals - '1', '2', etc Minus sign - '-' Decimal point - '.'.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/94
Parameters:
Char - the character to check [INPUTS]
- [OUTPUTS]
Returns:
TRUE - This could be the first char of a number FALSE - Sorry, but it's definitely not a number

Errors: -

Definition at line 519 of file convert.cpp.

00520 {
00521     return (    (StringBase::IsNumeric(Char)) ||
00522                 (Char == MinusSign) ||
00523                 (Char == DecimalPoint)
00524             );
00525 }

BOOL Convert::IsCharUnitType TCHAR  Char  )  [static]
 

Checks to see if this char could be part of a string that specifies a unit We have to allow most chars so that arbitrary units can be defined like such as pounds, dollars or percentages Illegal unit specifier chars are :- ASCII value <= ' ' Numericals - '1', '2', etc Minus sign - '-' Decimal point - '.' Thousand separator - ',' as in "10,000".

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/94
Parameters:
Char - the character to check [INPUTS]
- [OUTPUTS]
Returns:
TRUE - This could be part of a unit type specifier FALSE - Sorry, but it's either a white space or a number

Errors: -

Definition at line 489 of file convert.cpp.

00490 {
00491     return (    (unsigned(Char) > unsigned(TEXT(' '))) &&
00492                 (!StringBase::IsNumeric(Char)) &&
00493                 (Char != MinusSign) &&
00494                 (Char != DecimalPoint) &&
00495                 (Char != ThousandSep)
00496             );
00497 } 

BOOL Convert::LongToString INT32  Number,
StringBase OutputString
[static]
 

Converts a INT32 to a its string equivalent.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/9/93
Parameters:
Number - The number you want turning into a string [INPUTS]
OutputString - The string that gets created [OUTPUTS]
Returns:
TRUE if the conversion worked, false otherwise
See also:
StringToLong

Definition at line 1049 of file convert.cpp.

01050 {
01051     OutputString -> Empty();
01052 
01053     if (Number < 0)
01054     {
01055         TCHAR   buff[2] ;
01056         buff[0] = TEXT('-');
01057         buff[1] = TEXT('\0');
01058 
01059         *OutputString += String_8(buff);
01060         Number = -Number;
01061         
01062     }
01063     
01064     NumberToString( Number, OutputString );
01065     
01066     return TRUE;
01067 }

BOOL Convert::MillipointsToString double  MpValue,
UnitType  TheUnit,
StringBase OutputString,
INT32  DecimalPlaces = -1
[static]
 

Convert a number in MpValue to a string representation of that number in the given units. ie converting 72000 millipoints to inches would give the string '1in'. If DecimalPlaces = -1 then use the default preference value which the user has specified. See Also: DocUnitList.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> (rewritten by MarkN to use new units system - 6/7/94)
Date:
1/9/93
Parameters:
MpValue - The number of millipoints to be converted [INPUTS] TheUnit - The units that you need the result in OutputString - Stirng to put value into (See outputs) DecimalPlaces - The number of Decimal places required (0-3). This defaults to -1 which means use the default preference value.
OutputString - pointer to a string that is big enough to hold [OUTPUTS] the resulting number plus its type (ie 12.45cm)
Returns:
TRUE if all went well and the string is valid, FALSE otherwise

Definition at line 959 of file convert.cpp.

00961 {
00962     ERROR2IF(OutputString == NULL,FALSE,"MillipointsToString NULL output string supplied");
00963     // Decimal places will be -1 if the default number is to be used.
00964     
00965     double Value = 1.0;
00966     String_32 Specifier;
00967     TCHAR p[256], format[256], dpformat[256];
00968     
00969     DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
00970     DocUnitList FactoryDefUnits;
00971     if(pDocUnitList==NULL)
00972     {
00973         // certain classes (eg OpDescriptors) may want to call this function to set
00974         // values in controls after they have been read in by the bars/dialogs etc...
00975         // However at that point (Document::GetCurrent() == NULL) so you can't get
00976         // a DocUnitList from the current doc. Hence create our own default units
00977         FactoryDefUnits.Init();
00978         FactoryDefUnits.MakeDefaultUnits();
00979         pDocUnitList = &FactoryDefUnits;
00980     }
00981 
00982     Unit* pUnit = pDocUnitList->FindUnit(TheUnit);
00983 
00984     // Find out how many Units MpValue represents
00985     Value = MpValue / pUnit->GetMillipoints();
00986 
00987     // Get the specifier of the units we're in
00988     Specifier = pUnit->GetSpecifier();
00989 
00990     // check if we want the default number of decimal places
00991     if (DecimalPlaces == -1) DecimalPlaces = NumDecimalPlaces;
00992 
00993     //_stprintf(dpformat,"%%.%df",DecimalPlaces);   // Makes "%.xf" where x is num dp
00994     // Makes the output form "%.xf" where x is num dp.
00995     // %g instead of %f gives leading zero supression but then requires number significant
00996     // figures rather than number of decimal places.
00997     camSnprintf( dpformat, 256, TEXT("%%.%df"), DecimalPlaces) ;
00998 
00999     // Create the string to stick in an editable field (or wherever you like)
01000     if (pUnit->IsPrefix())
01001     {
01002         // Prefix units so show units followed by value
01003         camSnprintf( format, 256, _T("%%s%s"), (LPCTSTR) dpformat );                // ie. %s %.3f
01004         camSnprintf( p, 256, format, (LPCTSTR)Specifier, (double)Value );           // uses FP
01005         *OutputString = p;
01006         // Look for all zeros after decimal point and if so then remove
01007         //StripTrailingZeros(OutputString);
01008     }
01009     else
01010     {
01011         // Suffix units so show value followed by units
01012         camSnprintf( p, 256, dpformat, (double)Value );                     // uses FP
01013         *OutputString = p;
01014 
01015         // Look for all zeros after decimal point and if so then remove
01016         StripTrailingZeros(OutputString);
01017 
01018         // Finally, add in the unit specifier
01019         *OutputString += Specifier;
01020     }
01021 
01022     
01023     // Extra bodge required so that if the user has specified display values using
01024     // a non full stop to show decimal points then we must replace the point that
01025     // is present by the specified character.
01026     if (DecimalPoint != '.')
01027     {
01028         ReplaceDecimalPoint(OutputString);
01029     }
01030     
01031     return TRUE;
01032 }

void Convert::NumberToString MILLIPOINT  Number,
StringBase MyString
[static]
 

Appends the string representation of the given number to the end of MyString.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/9/93
Parameters:
Number - The number to be turned into a string [INPUTS]
MyString - the string is appended to this string [OUTPUTS]

Definition at line 904 of file convert.cpp.

00905 {
00906     INT32  Factor = 1;
00907     TCHAR ch[2]; 
00908     ch[1] = TEXT('\0');
00909     
00910     // Get a factor that 
00911     while (Factor*10 <= Number)
00912         Factor *= 10;
00913 
00914     while (Factor > 1)
00915     {
00916         // calculate the most significant digit and remove it from the number
00917         INT32 Digit = INT32(Number / Factor);
00918         ch[0] = TEXT('0') + Digit;
00919         *MyString += String_8(ch);
00920         
00921         // Add the digit into the string
00922         Number = Number - (Digit*Factor);
00923         Factor /= 10;
00924     }
00925 
00926     // add in the last character
00927     ch[0] = TEXT('0') + (INT32)Number;
00928     *MyString += String_8(ch);
00929     
00930 }

BOOL Convert::ReadNumber const StringBase Str,
INT32 *  pPos,
double *  pResult
[static]
 

General purpose routine for extracting the number from a string E.g. "42cm45.7mm" with *pPos == 0 returns TRUE with *pResult and 42.0 & *pPos == 2 "42cm-45.7mm" with *pPos == 4 returns TRUE with *pResult and -45.7 & *pPos == 9.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/94
Parameters:
pStr - Ptr to the string to get value from [INPUTS] pPos - *pPos = the pos to start scannning the string from (0 is first char) pResult - Ptr to a double
*pPos is the pos the scanning stopped [OUTPUTS] pResult = The number represented at the specified portion of the string
Returns:
TRUE - a valid number was read FALSE - something's a bit dodgey about that number mate

Errors: -

Definition at line 613 of file convert.cpp.

00614 {
00615     INT32           len         = Str.Length();
00616     const TCHAR    *pChar       = Str;
00617     BOOL            IsNegative  = FALSE;
00618     double          Number      = 0.0;
00619 
00620     //Added for DBCS Strip leading crap
00621     while (*pPos < len && iswspace(pChar[*pPos]))  //while (*pPos < len && pChar[*pPos] <= ' ')
00622         (*pPos)++;
00623     
00624     // Check for a minus sign; Added for DBCS
00625     if( pChar[*pPos] == MinusSign ) //if ( pChar[*pPos] == MinusSign )
00626     {
00627         IsNegative = TRUE;
00628         (*pPos)++;
00629         if (*pPos >= len)   return FALSE;
00630     }
00631     
00632     // Get the actual number                                        Added for DBCS                                  
00633     while( *pPos < len && 
00634         ( StringBase::IsNumeric(pChar[*pPos]) || 
00635            pChar[*pPos] == ThousandSep ) )//|| pChar[*pPos] == ThousandSep) )
00636     {
00637         //Added for DBCS
00638         if (pChar[*pPos] != ThousandSep ) //if (pChar[*pPos] != ThousandSep)
00639         {
00640             Number = (Number * 10.0) + ( pChar[*pPos] - TEXT('0') );
00641         }
00642         (*pPos)++;
00643     }
00644 
00645     // Check for a decimal place; Added for DBCS 
00646     if ( pChar[*pPos] == DecimalPoint) //if ( pChar[*pPos] == DecimalPoint )
00647     {
00648         (*pPos)++;
00649         if (*pPos < len)    // If the string ends in a DP, then we return the number now
00650         {   
00651             // Otherwise, we continue reading the fractional part of the string...
00652             INT32 DecimalFactor = 10;
00653             while ( *pPos < len  &&  StringBase::IsNumeric(pChar[*pPos]) )
00654             {
00655                 Number += (double)( pChar[*pPos] - TEXT('0') ) / DecimalFactor;
00656                 DecimalFactor *= 10;
00657                 (*pPos)++;
00658             }
00659         }
00660     }
00661 
00662     // If the number started with a minus sign, then make sure it is negative
00663     if (IsNegative)
00664         Number = -Number;
00665 
00666     *pResult = Number;
00667     return TRUE;
00668 }

BOOL Convert::ReadUnitType const StringBase Str,
INT32 *  pPos,
UnitType pUnitType
[static]
 

General purpose routine for extracting the unit type from a string E.g. "42cm45mm" with *pPos = 2 returns TRUE with *pUnitType == CENTIMETRES & *pPos == 4 "42cm45mm" with *pPos = 6 returns TRUE with *pUnitType == MILLIMETRES & *pPos == 8.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/94
Parameters:
pStr - Ptr to the string to get unit type [INPUTS] pPos - *pPos = the pos to start scannning the string from (0 is first char) pUnitType - Ptr to a UnitType
*pPos is the pos the scanning stopped [OUTPUTS] pUnitType is the units represented by the string
Returns:
TRUE - units have been recognised and value stored in *pUnitType is valid OR no units have been specified and *pUnitType == NOTYPE FALSE - What are these units eh?

Errors: -

Definition at line 549 of file convert.cpp.

00550 {
00551     INT32                   len = Str.Length();
00552     const TCHAR        *pChar = (const TCHAR *)Str;
00553     TCHAR               UnitCharArray[256]; 
00554     INT32 i;
00555     BOOL ok = TRUE;
00556     //Added for DBCS; Strip leading crap
00557     while (*pPos < len && iswspace(pChar[*pPos])) //while (*pPos < len && pChar[*pPos] <= ' ')
00558           (*pPos)++ ;           
00559 
00560     i = 0;
00561     if (IsCharUnitType(pChar[*pPos]))
00562     {
00563         // Copy unit-specifying chars into UnitCharArray
00564         // NO LONGER copes with wierd unit specifiers that contain numbers too. e.g. "nu2", "b54c"
00565         // as of 18/5/95 (MarkN)
00566         while ( *pPos < len && (IsCharUnitType(pChar[*pPos])) && i<256) // || StringBase::IsNumeric(pChar[*pPos])) && 
00567             UnitCharArray[i++] = pChar[(*pPos)++];
00568     }
00569 
00570     UnitCharArray[i] = 0;   // Visit the string Terminator (I'm a null char; that's what I do)
00571 
00572     String_256 UnitString = UnitCharArray;
00573     
00574     //char changed to TCHAR for DBCS 
00575 //  TCHAR* p = UnitString;  // for debugging purposes
00576     DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
00577 
00578     if (!UnitString.IsEmpty())
00579     {
00580         // if the string isn't empty, then we must recognise the unit
00581         // otherwise we'll have to fail
00582         *pUnitType = pDocUnitList->FindUnitType(UnitString);
00583         ok = (*pUnitType != NOTYPE);
00584     }
00585     else
00586         *pUnitType = NOTYPE;    // Empty string means NOTYPE means use a default type from somewhere
00587     
00588 
00589     return (ok);
00590 }

BOOL Convert::ReplaceDecimalPoint StringBase pString  )  [static]
 

Searches the specified string for a decimal point and replaces this with the specified DecimalPoint character. It assumes that a check has been made already to see if we are using a non-decimal point character and so this routine is only called when the replacement is actually required. This MUST ALWAYS be after the StripTrailingZeros code. Otherwise, the StripTrailingZeros code would have to search for two items, a decimal point and the international form of the decimal point.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/1/95
Parameters:
pString - Pointer to the string to be parsed. [INPUTS]
pString - Pointer to the string that should now have the proper decimal point [OUTPUTS]
Returns:
TRUE if the conversion worked, false otherwise
See also:
MillipointsToString; DimScale::ConvertToUnits; DoubleToString; Convert::StripTrailingZeros;

Definition at line 390 of file convert.cpp.

00391 {
00392     // Could probably be optimised to be quicker
00393 
00394     // Make up a string of the new decimal point character 
00395     String_8 InsertStr;
00396     ((TCHAR *) InsertStr)[0] = DecimalPoint;
00397     ((TCHAR *) InsertStr)[1] = 0;
00398 
00399     // Work out the position of the current decimal point character, - 1 if none
00400     INT32   Position;
00401     String_8            InsertMark(_R(IDS_CONVERT_DP_CHAR));
00402 
00403     Position = pString->Sub(InsertMark);
00404     
00405     // If decimal point was found then put the new decimal point character in place 
00406     if (Position > 0)
00407     {
00408         pString->Remove(Position, 1);
00409         pString->Insert(InsertStr, Position);          
00410     }
00411     
00412     return TRUE;
00413 }

BOOL Convert::SetDecimalPointChar char  NewDecimalPoint  )  [static]
 

Allows the setting up of the character to separate whole part of number from the fractional part in displayed numbers e.g. 56.79 This is read from the OS at present. This function just provided just in case we wish to overide this in the future.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
True if set correctly, False otherwise.
See also:
GetDecimalPointChar(); GetCurrentNumberFormat();

Definition at line 303 of file convert.cpp.

00304 {
00305     // Don't allow a blank to be set.
00306     //if (NewDecimalPoint = '') return FALSE;
00307 
00308     DecimalPoint = NewDecimalPoint;
00309 
00310     return TRUE;
00311 }

BOOL Convert::SetNumberDecimalPlaces UINT32  NewDPs  )  [static]
 

Allows the setting up of the number of decimal places to display to by default This is read from the OS at present. This function just provided just in case we wish to overide this in the future.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
NewDPs new number of decimal places to use [INPUTS]
- [OUTPUTS]
Returns:
True if set correctly, False otherwise.
See also:
GetNumberDecimalPlaces(); GetCurrentNumberFormat();

Definition at line 357 of file convert.cpp.

00358 {
00359     // Set some limit to the number allowed
00360     if (NewDPs > 9) return FALSE;
00361 
00362     NumDecimalPlaces = NewDPs; 
00363 
00364     return TRUE;
00365 }

BOOL Convert::SetThousandsSepChar char  NewThousandsSep  )  [static]
 

Allows the setting up of the character to be used to separate thousands in displayed numbers e.g. 10,000. This is read from the OS at present. This function just provided just in case we wish to overide this in the future.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/9/95
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
True if set correctly, False otherwise.
See also:
GetThousandsSepChar(); GetCurrentNumberFormat();

Definition at line 331 of file convert.cpp.

00332 {
00333     // Don't allow a blank to be set.
00334     //if (NewThousandsSep = '') return FALSE;
00335 
00336     ThousandSep = NewThousandsSep;
00337 
00338     return TRUE;
00339 }

UINT32 Convert::StringToBytes const StringBase Str,
BOOL *  Valid
[static]
 

Takes a string with a textual description of an amount of memory, and returns the amount of bytes described by the string.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/1/95
Parameters:
pStr - pointer to all manner of memory amount specifying strings [INPUTS] such as "1024k", "1024 bytes", "1024", "1048576", "1Mb". (NB - The above will all return 1024 (and Valid == TRUE)).
Valid - used to flag a valid result. Invalid results will return 0 and [OUTPUTS] flag this variable to FALSE. Any non-numerically starting strings will cause this invalid state. Leading spaces shouldn't pose a problem...
Returns:
Number of bytes described by input string, so "1k" would produce 1024...

Errors: At present we only use simple string matching, so "100 Tera-bytes" will return 100, as Tera is not supported and the bytes section is matched. Also "200 trams" will return 200*1024*1024, as the 'm' of trams is matched as flagging a mega-byte.

See also:
-

Definition at line 1285 of file convert.cpp.

01286 {
01287     // Set up bad return value until we are fairly happy with the string 
01288     *Valid = FALSE;
01289     
01290     //changed char to TCHAR for DBCS
01291     const TCHAR        *CharStr = (const TCHAR *)Str;   
01292 
01293     double  Number  = 0.0;
01294     INT32   Pos     = 0;
01295     UINT32  ret     = 0;
01296     // Try and read the value in using are routine
01297     // Cannot use atof as does not cope with non-standard decimal point and thousand
01298     // separator characters.
01299 //  UINT32 ret=_ttoi(CharStr);                              // Rip the numbers from the start
01300     BOOL ok = ReadNumber(Str, &Pos, &Number);
01301     if (!ok) return 0;                                      // bad number so return invalid 
01302 
01303     // If negative then return invalid and zero.
01304     if (Number < 0) return 0;
01305     // If bigger than what can be held in a UINT32 then return the maximum and FALSE. 
01306     if (Number > (double)UINT32_MAX) return UINT32_MAX;
01307      
01308     // We have what looks like a fairly valid number so set return flag True;
01309     *Valid = TRUE;
01310 
01311     // If value is zero then return with no more checking as not relevent
01312     if (Number == 0) return (0);
01313 
01314     if (    cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_SMALL_K)) /*"k"*/)
01315          || cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_LARGE_K)) /*"K"*/) )
01316     {
01317         // Check if K or K is in the string and if so multiply by 1024 
01318         Number = Number*1024;               // Kilobyte value
01319     }
01320     else if (   cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_SMALL_M)) /*"m"*/)
01321              || cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_LARGE_M)) /*"M"*/) )
01322     {
01323         // Check if M or m is in the string and if so multiply by 1024 by 1024 
01324         Number = Number*1024*1024;          // Megabyte value
01325     }
01326     else if (   cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_SMALL_G)) /*"g"*/)
01327              || cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_LARGE_G)) /*"G"*/) )
01328     {
01329         // Check if G or g is in the string and if so multiply by 1024 by 1024 by 1024 
01330         Number = Number*1024*1024*1024;     // Gigabyte value
01331     }
01332     else if (   cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_SMALL_BYTE)) /*"byte"*/)
01333              || cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_MEDIUM_BYTE)) /*"Byte"*/)
01334              || cc_lstrstr(CharStr, (TCHAR *)String_16(_R(IDS_CONVERT_LARGE_BYTE)) /*"BYTE"*/) )
01335     {
01336         // Check if byte or variation of specified in which case just return the value 
01337         // Number = Number;                 // straight byte value
01338     }
01339     // if none of the above then assume value is in bytes and hence do nothing
01340 
01341     // If bigger than what can be held in a UINT32 then return the maximum and FALSE. 
01342     if (Number > (double)UINT32_MAX) return UINT32_MAX;
01343 
01344     // We just want the interger part of the number specified as fractional parts are non-valid
01345     ret = (UINT32)Number;
01346 TRACEUSER( "Neville", _T("%s -> %d\n"), (char *)CharStr, ret );     
01347          
01348     return ret;     
01349 }

BOOL Convert::StringToComponents const StringBase str,
double *  pValue,
UnitType pUnits
[static]
 

General purpose routine for extracting the value and unit components of a string. E.g.1 the string "42.6in" would extract the value 42.6 and the unit type INCHES E.g.2 The string "42.6" would give *pValue=42.6,*pUnits=NOTYPE, and TRUE is returned. E.g.3 "4in5in" gives *pValue=9,*pUnits=INCHES, and returns TRUE E.g.4 "1in2cm" gives *pValue = 1.79,*pUnits=INCHES, and returns TRUE In this case it takes the first unit specified as the dominant unit (INCHES in this case), so the result is 1in plus 2cm converted to INCHES which is about 0.79in.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/6/94 (changed considerably on 27/6/94 by Markn)
Parameters:
InputString - The string to get values from [INPUTS] pValue - The value of the numerical part of the string pUnits - The unit value of the unit part of the string if no units are specified, *pUnits = NOTYPE
- [OUTPUTS]
Returns:
TRUE - Valid string FALSE - Something wrong with the string

Errors: This function can fail if the string was not a valid one. ie the string '12zx'. zx is not a unit that Camelot understands and so fails.

Definition at line 733 of file convert.cpp.

00734 {
00735     TCHAR*      MyString;
00736     TCHAR       Char;
00737     INT32       Pos         = 0;
00738     INT32       len         = str.Length();
00739     String_256  InputString( str );
00740 //  BOOL        IsNegative  = FALSE;
00741     double      Result      = 0.0;
00742     UnitType    MainUnits   = NOTYPE;
00743     
00744     *pValue = 1.0;
00745     *pUnits = INCHES;
00746     
00747     // Make sure that the string is in lower case as per SI units
00748     InputString.toLower();
00749     MyString = (TCHAR *)InputString;
00750 
00751     // I might consider adding this to the base class StringBase, BUT at the moment
00752     // its not really necessary ....
00753     //
00754     // JCF: fixed this to be internationally portable ie. what is alphanumeric in
00755     // your language?   
00756     //
00757     while (Pos < len)
00758     {
00759         if (!StringBase::IsAlphaNumeric(MyString[Pos]) &&
00760             MyString[Pos] != TEXT('-') &&
00761             MyString[Pos] != TEXT('.') &&
00762             MyString[Pos] != TEXT(','))
00763         {
00764             return FALSE;
00765         }
00766 
00767         Pos++;
00768     }
00769 
00770     Pos = 0;
00771 
00772     while (Pos < len)
00773     {
00774         double Number = 0.0;        
00775         UnitType Units;
00776 
00777         // Strip leading crap   Added for DBCS
00778         while (Pos < len && iswspace( MyString[Pos] ))   //while (Pos < len && MyString[Pos] <= ' ')
00779                Pos++;
00780     
00781         Char = MyString[Pos];
00782         
00783         if (IsCharStartOfNumber(Char))
00784         {
00785             if (!ReadNumber(InputString,&Pos,&Number))
00786                 return FALSE;
00787             if (!ReadUnitType(InputString,&Pos,&Units))
00788                 return FALSE;
00789         }
00790         else
00791         {
00792             if (!ReadUnitType(InputString,&Pos,&Units))
00793                 return FALSE;
00794             if (!ReadNumber(InputString,&Pos,&Number))
00795                 return FALSE;
00796         }
00797         
00798         if (MainUnits == NOTYPE) MainUnits = Units;
00799 
00800         if (MainUnits != Units && MainUnits != NOTYPE)
00801             Number = ConvertToNewUnits(Number,Units,MainUnits);
00802 
00803         Result += Number;
00804     }
00805 
00806     *pUnits = MainUnits;
00807     *pValue = Result;
00808 
00809     return TRUE;
00810 }

BOOL Convert::StringToDouble const StringBase InputString,
double *  Number
[static]
 

Converts a string into its double equivalent.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/12/94
Parameters:
InputString - The string that you want turning into a double [INPUTS]
Number - The number you want turning into a string [OUTPUTS]
Returns:
TRUE if the conversion worked, false otherwise
See also:
DoubleToString
Used to be a bodge as atof() doesn't work in unicode but converted to use the other functions which should do it properly.

Definition at line 1183 of file convert.cpp.

01184 {
01185 //#if UNICODE
01186 //#error "I'm screwed! atof() doesn't work for UNICODE"
01187 //#else
01188 //  *Number = atof((char *)*InputString);
01189 //  return(TRUE);
01190 //#endif
01191 
01192     // Cannot use atof as does not cope with a non-decimal point character which
01193     // the user may be specifying so use our form of atof.
01194     // atof will also allow say 26.98mm where we should really be erroring.
01195     // ReadNumber ignores everything after a dodgy decimal point which is not correct. 
01196     // StringToComponents will include units as well. We do not want this part so ignore it.
01197     UnitType Units;
01198     BOOL ok = StringToComponents(InputString,Number,&Units);
01199 
01200     // Check if units are NOTYPE and if not then return failure.
01201     if (Units != NOTYPE)
01202         return FALSE;
01203 
01204     return ok;
01205 }

double Convert::StringToDouble const StringBase InputString,
UnitType  Default,
BOOL *  ValidString
[static]
 

Convert the string into a floating point representation of the number of millipoints. eg '1in' would be converted to 72000.0 millipoints. Does NOT cope with '0.25in0.75in' - this would return 18000.0 millipoints instead of 72000.0 millipoints. If you want a MILLIPOINT value, use StringToMillipoint to ensure correct rounding.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/3/94 - modified 14/6/94
Parameters:
pInputString - The string to convert to its millipoint value [INPUTS] Default - the Unit type to be used if no other units have been specified in the string
ValidString - The Address of a bool. This will be set to TRUE if [OUTPUTS] the function converted the string without error, FALSE otherwise.
Returns:
double - the number of Millipoints represented by the string

Errors: This function can fail if the string was not a valid one. ie the string '12zx'. zx is not a unit that StringToDouble understands and so fails.

See also:
StringToMillipoint

Definition at line 838 of file convert.cpp.

00839 {
00840     double      Number = 1.0;
00841     UnitType    Units;
00842 
00843     *ValidString = StringToComponents( InputString,&Number,&Units);
00844 
00845     if (Units == NOTYPE)
00846         Units = Default;
00847 
00848     if (*ValidString)
00849     {
00850         DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
00851         Unit* pUnit = pDocUnitList->FindUnit(Units);
00852         return (Number * pUnit->GetMillipoints());      // Get the number to millipoints and multiply
00853     }
00854     else
00855         return 72000.0;
00856 }

BOOL Convert::StringToLong const StringBase InputString,
INT32 *  pNumber
[static]
 

Converts a string into its INT32 equivalent.

Author:
Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/9/93
Parameters:
InputString - The string that you want turning into a number [INPUTS]
Number - The number you want turning into a string [OUTPUTS]
Returns:
TRUE if the conversion worked, false otherwise
See also:
LongToString

Definition at line 1132 of file convert.cpp.

01133 {
01134     // Get a pointer version of the string
01135     const TCHAR* pMyString = (const TCHAR*)InputString;
01136     INT32 nLength = InputString.Length();
01137     INT32 nPos = 0;
01138     
01139     // Check for a minus sign - added for DBCS
01140     BOOL fIsNegative = FALSE;
01141     if (pMyString[nPos] == TEXT('-') )   // if (pMyString[Pos] == TEXT('-'))
01142     {
01143         fIsNegative = TRUE;
01144         nPos++;
01145         if (nPos >= nLength) return 0;
01146     }
01147             
01148     // Get the actual number
01149     INT32 nTotal     = 0;
01150     while (nPos < nLength && StringBase::IsNumeric(pMyString[nPos]))
01151     {
01152         nTotal = (nTotal * 10) + pMyString[nPos] - TEXT('0');
01153         nPos++;
01154     }
01155     
01156     // If we have not read in the whole string, then it was not valid
01157     if (nPos < nLength && !StringBase::IsSpace(pMyString[nPos])) return FALSE;  
01158 
01159     // If the number started with a minus sign, then make sure it is negative
01160     if (fIsNegative) nTotal = -nTotal;
01161 
01162     *pNumber = nTotal;
01163     return TRUE;
01164 }

MILLIPOINT Convert::StringToMillipoints const StringBase InputString,
UnitType  Default,
BOOL *  ValidString
[static]
 

Convert the string into a MILLIPOINT representation of the number of millipoints. eg '1in' would be converted to 72000 millipoints. Does NOT cope with '0.25in0.75in' - this would return 18000 millipoints instead of 72000 millipoints.

Author:
Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/3/94 - modified 14/6/94
Parameters:
pInputString - The string to convert to its millipoint value [INPUTS] Default - the Unit type to be used if no other units have been specified in the string
ValidString - The Address of a bool. This will be set to TRUE if [OUTPUTS] the function converted the string without error, FALSE otherwise.
Returns:
MILLIPOINT - An integer version of the number of Millipoints represented by the string

Errors: This function can fail if the string was not a valid one. ie the string '12zx'. zx is not a unit that StringToDouble understands and so fails.

Definition at line 883 of file convert.cpp.

00884 {
00885     double result = StringToDouble( InputString,Default,ValidString);
00886 
00887     return (MILLIPOINT)(result+0.5);
00888 }

BOOL Convert::StripTrailingZeros StringBase pString  )  [static]
 

Strip trailing zeros (& decimal point) from a string containing a decimal number This MUST ALWAYS be called before the replace decimal point character code. Otherwise, we would have to search for two items, a decimal point and the international form of the decimal point.

Author:
Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/7/95
Parameters:
pString - string to have trailing zeros removed [INPUTS]
pString - string with trailing zeros removed [OUTPUTS]
Returns:
FALSE if fails
See also:
MillipointsToString; DimScale::ConvertToUnits; DoubleToString; Convert::ReplaceDecimalPoint;

Definition at line 433 of file convert.cpp.

00434 {
00435     // Get the decimal point character that we are going to search for into one of our
00436     // strings. This MUST be the decimal point character as this is ALWAYS called before
00437     // the replace decimal point character. Otherwise, we would have to search for two
00438     // items.
00439     String_8 DPChar(_R(IDS_CONVERT_DP_CHAR));
00440     const String_8 ZeroChar(_R(IDS_CONVERT_ZERO_CHAR));
00441 
00442     // if there is a decimal point in the string ...
00443     if (pString->Sub(DPChar)!=-1)
00444     {
00445         // skip backwards over trailing zeros
00446         String_8        TmpStr;
00447         INT32               NewStrLen = pString->Length();
00448         do
00449         {
00450             NewStrLen-=1;
00451             pString->Mid(&TmpStr,NewStrLen,1);
00452         } while (TmpStr==ZeroChar);
00453 
00454         // if this previous char is NOT a decimal point DO NOT strip it
00455         if (TmpStr!=DPChar)
00456             NewStrLen+=1;
00457 
00458         // remove the trailing zeros from the original string
00459         pString->Left(pString,NewStrLen);
00460     }
00461 
00462     return TRUE;
00463 }


Member Data Documentation

char Convert::DecimalPoint = '.' [static, protected]
 

Definition at line 200 of file convert.h.

char Convert::MinusSign = '-' [static, protected]
 

Definition at line 202 of file convert.h.

UINT32 Convert::NumDecimalPlaces = 2 [static, protected]
 

Definition at line 203 of file convert.h.

char Convert::ThousandSep = ',' [static, protected]
 

Definition at line 201 of file convert.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:11 2007 for Camelot by  doxygen 1.4.4