Implementation of utility functions.
More...
Go to the source code of this file.
|
char * | substring (const char *string, int startPosition, int length) |
| Copies a substring (heap-allocated) from the passed string. If fails when allocating memory for the substring, it exits with EXIT_ALLOC_FAILURE exit code.
|
int | offsetFromNext (const char *string, char character, int startPosition) |
| Counts the offset in the string between the position and the next occoruncy of the passed char.
|
int | count (const char *string, char character, int startPosition) |
| Counts the number of occoruncies in the string, from a passed position, of the passed char.
|
bool | containsFrom (const char *string, char character, int startPosition) |
| Checks if there is an occoruncy of the passed char from the passed position in the passed string.
|
bool | containsSubstringFrom (const char *string, const char *subString, int startPosition) |
| Checks if there is an occoruncy of the passed substring from the passed position in the passed string.
|
bool | isDecimalDigit (char character) |
| Checks if a char is a decimal digit.
|
bool | isHexDigit (char character) |
| Checks if a char is a hexadecimal digit (not case sensitive).
|
int | decimalDigitToInt (char digit) |
| If is a decimal digit, converts it to int; Otherwise returns ASCII integer representation of the passed char.
|
int | hexDigitToInt (char digit) |
| If is a hexadecimal digit (not case sensitive), converts it to int; Otherwise returns ASCII integer representation of the passed char.
|
int | evalutateBase (char *number) |
| Evalutates the base of the number (by finding the biggest digit up to hexadecimal digit F) and returns it. If the string contains a non-digit char (up to hexadecimal digit F), returns -1.
|
int | nDigits (int number) |
| Evalutates the number of digits of a number. The time complexity of this function is constant (O(1)).
|
Implementation of utility functions.
Definition in file utility.c.
◆ containsFrom()
bool containsFrom |
( |
const char * | string, |
|
|
char | character, |
|
|
int | startPosition ) |
Checks if there is an occoruncy of the passed char from the passed position in the passed string.
- Parameters
-
string | The string to check in. |
character | The char to look for. |
startPosition | The position from which starts. |
- Returns
- True if an occoruncy is found, false otherwise.
Definition at line 63 of file utility.c.
◆ containsSubstringFrom()
bool containsSubstringFrom |
( |
const char * | string, |
|
|
const char * | subString, |
|
|
int | startPosition ) |
Checks if there is an occoruncy of the passed substring from the passed position in the passed string.
- Parameters
-
string | The string to check in. |
subString | The substring to look for. |
startPosition | The position from which starts. |
- Returns
- True if an occoruncy is found, false otherwise.
Definition at line 75 of file utility.c.
◆ count()
int count |
( |
const char * | string, |
|
|
char | character, |
|
|
int | startPosition ) |
Counts the number of occoruncies in the string, from a passed position, of the passed char.
- Parameters
-
string | The string to count from. |
character | The char to count on the occoruncies in the string. |
startPosition | The start position in the string to count from. |
- Returns
- Returns the number of occoruncies of the char in the string. If there are not occoruncies of the char in the passed string, returns 0.
Definition at line 50 of file utility.c.
◆ decimalDigitToInt()
int decimalDigitToInt |
( |
char | digit | ) |
|
If is a decimal digit, converts it to int; Otherwise returns ASCII integer representation of the passed char.
- Parameters
-
digit | The char to convert. |
- Returns
- The digit as an integer if the char is a decimal digit, ASCII integer representation of the passed char otherwise.
Definition at line 105 of file utility.c.
◆ evalutateBase()
int evalutateBase |
( |
char * | number | ) |
|
Evalutates the base of the number (by finding the biggest digit up to hexadecimal digit F) and returns it. If the string contains a non-digit char (up to hexadecimal digit F), returns -1.
- Parameters
-
number | The number in text format. |
- Returns
- The base of the number, if it is valid. Otherwise -1.
Definition at line 123 of file utility.c.
◆ hexDigitToInt()
int hexDigitToInt |
( |
char | digit | ) |
|
If is a hexadecimal digit (not case sensitive), converts it to int; Otherwise returns ASCII integer representation of the passed char.
- Parameters
-
digit | The char to convert. |
- Returns
- The digit as an integer if the char is a hexadecimal giti, ASCII integer representation of the passed char otherwise.
Definition at line 109 of file utility.c.
◆ isDecimalDigit()
bool isDecimalDigit |
( |
char | character | ) |
|
Checks if a char is a decimal digit.
- Parameters
-
character | The char to check. |
- Returns
- True if the char is decimal digit, false otherwise.
Definition at line 97 of file utility.c.
◆ isHexDigit()
bool isHexDigit |
( |
char | character | ) |
|
Checks if a char is a hexadecimal digit (not case sensitive).
- Parameters
-
character | The char to check. |
- Returns
- True if the char is a hexadecima digit, false otherwise.
Definition at line 101 of file utility.c.
◆ nDigits()
int nDigits |
( |
int | number | ) |
|
Evalutates the number of digits of a number. The time complexity of this function is constant (O(1)).
- Parameters
-
number | The number to evalutate. |
- Returns
- The number of digits.
Definition at line 138 of file utility.c.
◆ offsetFromNext()
int offsetFromNext |
( |
const char * | string, |
|
|
char | character, |
|
|
int | startPosition ) |
Counts the offset in the string between the position and the next occoruncy of the passed char.
- Parameters
-
string | The string where to search the occoruncy. |
character | The char to search to. |
startPosition | The position where to start |
- Returns
- The offset from the start position to the next occorncy of the char. Otherwise, if no more occoruncies occur, returns -1.
Definition at line 38 of file utility.c.
◆ substring()
char * substring |
( |
const char * | string, |
|
|
int | startPosition, |
|
|
int | length ) |
Copies a substring (heap-allocated) from the passed string. If fails when allocating memory for the substring, it exits with EXIT_ALLOC_FAILURE exit code.
- Parameters
-
string | String to copy from. |
startPosition | The position in str to start to copy from. |
length | The length of the substring. |
- Returns
- The substring (heap-allocated).
Definition at line 23 of file utility.c.