Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSHelper Class Reference

#include <CSHelper.h>


Static Public Member Functions

int convert (const char *start_string, int radix)
 string to number (with given radix)

bool replace (std::string &text, const std::string &oldValue, const std::string &newValue)
int colorPercent (int color, int percent)
 Gives the percentage of a color.


Member Function Documentation

int CSHelper::convert const char *  start_string,
int  radix
[static]
 

string to number (with given radix)

Definition at line 7 of file CSHelper.cpp.

Referenced by HTMLElement::getColorFromString().

00008 {
00009     char* string;
00010     char *pointer;
00011     int value=0;
00012     int tmp=0;
00013     int multiplier;
00014     int loop;
00015     int exponent=0;
00016     if ((start_string==0)||(radix==0))
00017     {
00018         return 0;
00019     }
00020     pointer=string=strdup(start_string); /* don't destroy start string */
00021 
00022     /* make the string entirely uppercase */
00023 
00024     while (*pointer!=(char)0)
00025     {
00026         if ((*pointer>='a')&&(*pointer<='z'))
00027         {
00028             *pointer+=('A'-'a');
00029         }
00030         pointer++;
00031     }
00032     
00033     /* decode the string backwards */
00034     pointer = string;
00035     while (*(pointer+1)!=0)
00036     {
00037         pointer++;
00038     }
00039     
00040     do
00041     {
00042         tmp=*pointer;
00043         if (tmp>'9')
00044         {
00045             tmp-=('A'-10);
00046         }
00047         else
00048         {
00049             tmp-='0';
00050         }
00051         /* Test for validity */
00052         if (tmp>=radix)
00053         {
00054             free(string);
00055             return 0;
00056         }
00057 
00058         /* Calculate the Multiplier */
00059         multiplier=1;
00060         for (loop=0;loop<exponent;loop++)
00061         {
00062             multiplier*=radix;
00063         }
00064         value+=tmp*multiplier;
00065 
00066         /* Increment the exponent */
00067         exponent++;
00068     }
00069     while(pointer--!=string);
00070 
00071     free(string);
00072     return value;
00073 }

bool CSHelper::replace std::string &  text,
const std::string &  oldValue,
const std::string &  newValue
[static]
 

Definition at line 76 of file CSHelper.cpp.

00077 {
00078     std::string newText;
00079     std::string rest;
00080     int posStart = strstr(text.c_str(), oldValue.c_str()) - text.c_str();
00081     if (posStart != -(int) (text.c_str()))
00082     {
00083         newText = text.substr(0, posStart);
00084     }
00085     else
00086     {
00087         return false;
00088     }
00089     newText = newText + newValue;
00090     
00091     int len = oldValue.size();
00092     if (posStart+len < text.size())
00093     {
00094         newText = newText + text.substr(posStart + len, text.size() - (posStart + len) );
00095     }
00096     text = newText;
00097     return true;
00098 }

int CSHelper::colorPercent int  color,
int  percent
[static]
 

Gives the percentage of a color.

Gives the percentage of the color. Each r ,g ,b value is calculated as percentage

Parameters:
color in RGB lile 0x102030 (r = 0x10, g = 0x20, b = 0x30)
percent percentage
Returns:
percent of the color in RGB, as above

Definition at line 104 of file CSHelper.cpp.

References colorPercent().

Referenced by colorPercent(), CSRoundedBorder::paint(), and CSBorder::paint().

00105 {
00106     int r = (((color)&0xff0000)>>16);
00107     int g = (((color)&0x00ff00)>>8);
00108     int b = (((color)&0x0000ff));
00109     int colorPercent;
00110     colorPercent =  (((r*percent)/100)<<16);
00111     colorPercent += (((g*percent)/100)<<8);
00112     colorPercent += ( (b*percent)/100);
00113     return colorPercent;
00114 }

Here is the call graph for this function:


Generated on Wed Jul 14 00:44:27 2004 for CSLib by doxygen 1.3.6