CS480-Projects/Preparation/Phase6/StringUtils.c
cdez fd87d9a54d Good Stopping Point for 480 Prep
+- Phase6 Preparation to Step 3.
2024-01-07 01:50:01 -07:00

245 lines
No EOL
6.9 KiB
C

// header files
#include "StringUtils.h"
// list of utils:
// string length
// getStringLength
// string copy
// copyString
// string concatenate
// catString
// string compare (<, >, =)
// compareString
// string substring get
// getSubString
// string substring find
// findSubString
// string set to lower
// toLowerCase
// string get to delimiter
// stringDelimiter
// string get to end of line
// stringEOL
// function implementations
/*
Name: catString
Process: concatenates two strings
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void catString(char *outString, const char *inString)
{
// no return, void.
}
/*
Name: compareString
Process: compares two strings as follows:
- if left string is alphabetically greater than the right string,
returns value greater than zero
- if left string is alphabetically less than the right string,
returns value less than zero
- if strings are alphabetically equal but one is longer,
longer one is greater
- otherwise, returns zero
Function input/parameters: c-style strings (char *) [first and second/left&right]
Function output/parameters: NONE
Function output/returned: results as specfifed above (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int compareString(const char *firstString, const char *secondString)
{
// return zero (temp)
return 0;
}
/*
Name: copyString
Process: copies string into new string variable, overwrites destination.
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void copyString(char *outString, const char *inString)
{
// no return, void.
}
/*
Name: getStringLength
Process: gets length of string from start to NULL_CHAR ('\0')
Function input/parameters: c-style string (char *)
Function output/parameters: NONE
Function output/returned: length of string (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int getStringLength(const char *stringIn)
{
// define variables
int stringLength = 0, currentCharacter = 0;
// get user input (not needed)
// do calculations
while (currentCharacter < STD_STR_LEN && stringIn[currentCharacter] != NULL_CHAR)
{
// increment string length
stringLength = stringLength + 1;
// increment currentCharacter
currentCharacter = currentCharacter + 1;
}
// display results (not needed)
// return success
return stringLength;
}
/*
Name: getSubString
Process: captures sub string within larger string
between two inclusive indices.
returns empty string if either index is out of range,
assumes enough memory in dest string
Function input/parameters: c-style string (char *)
start and end indices (int)
Function output/parameters: c-style destination string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength, malloc, copyString, free
*/
void getSubString(char *destStr, const char *sourceStr,
int startIndex, int endIndex)
{
// no return, void.
}
/*
Name: findSubString
Process: linear search for given substring within another string
Function input/parameters: c-style test string (char *),
c-style source string (char *)
Function output/parameters: NONE
Function output/returned: index of found substring, or
SUBSTRING_NOT_FOUND constant
if string not found
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int findSubString()
{
// return zero (temp)
return 0;
}
/*
Name: strToLowerCase
Process: iterates through string, sets any uppercase letter to lowercase
equivalent, does not affect any letter with an upper/lower diff.
Function input/parameters: c-style source string (char *)
Function output/parameters: c-style dest string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: toLowerCase
*/
void strToLowerCase()
{
// no return, void.
}
/*
Name: toLowerCase
Process: sets character to lowercase letter if uppercase letter,
returns character
Function input/parameters: character input (char)
Function output/parameters: NONE
Function output/returned: character output (char)
Device input/---: NONE
Device output/---: NONE
Dependencies: none
*/
char toLowerCase()
{
// return null character (temp)
return NULL_CHAR;
}
/*
Name: getStringToDelimiter
Process: captures a string from the input stream to a specified delimiter.
will consume the delimiter.
Function input/parameters: input stream (FILE *),
stops at specified character
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToDelimiter(FILE *inStream, char delimiter, char *capString)
{
// return false (temp)
return false;
}
/*
Name: getStringConstrained
Process: captures a string from the file stream with various constraints
Function input/parameters: input stream (FILE *),
clears leading non printable (bool),
clears leading space (bool),
stops at non printable (bool),
stops at specified delimiter (char)
will consume the delimiter.
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: fgetc
*/
bool getStringConstrained(FILE *inStream, bool clearLeadingNonPrintable,
bool clearLeadingSpace, bool stopAtNonPrintable,
char delimiter, char *capString)
{
// return false (temp)
return false;
}
/*
Name: getStringToLineEnd
Process: captures a string from the input stream to the end of the line
Function input/parameters: input file stream (FILE *)
Function output/parameters: c-style string (char *)
Function output/returned: success of operation (bool)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringConstrained
*/
bool getStringToLineEnd(FILE *inStream, char *capString)
{
// return false (temp)
return false;
}
/*
Name: ???
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/