-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringInteractions.h
218 lines (190 loc) · 7.2 KB
/
stringInteractions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* @file stringInteractions.h Header file of stringInteractions.c
* @author Valentin Koeltgen
*/
#ifndef LINEARALGEBRA_STRINGINTERACTIONS_H
#define LINEARALGEBRA_STRINGINTERACTIONS_H
#include <stdlib.h>
#include <stdio.h>
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Construction functions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* Read a string in a file stream
* This function read a string of any size in a given file stream. It will get all visible characters in the ASCII table
* @param current - The file stream where the string will be read
* @return string formed from the file stream
*/
char *readString(FILE *current);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Basic operator functions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* String length
* This function output the length of a string
* @note the \0 is not included in the count
* @param string
* @return
*/
int length(const char *string);
/**
* First word of a string
* This function return the first word of a string (surrounded by whitespaces)
* @param string - The string where to extract the first word
* @return first word
*/
char *firstWord(const char *string);
/**
* Compare strings
* This function compare 2 strings, it returns 1 if the first is shorter, 2 if the second is shorter and 0 if they are equal
* @param string1 - first string for comparison
* @param string2 - second string for comparison
* @return result of comparison
*/
char shorterString(const char *string1, const char *string2);
/**
* Search for string in a string
* This function verify if a given string is contained in another, it returns 1 if it does and 0 otherwise
* @param mainString - The string to check for the other string
* @param toSearch - The string to search
* @return result of search
*/
char containString(const char *mainString, const char *toSearch);
/**
* Verify if the string contains the character in order
* This function return 1 if the string contains the character in order and 0 if it doesn't
* @param string - String to scan for the characters
* @param charToSearch - Characters to search
* @return result of the scan
*/
char containCharInOrder(const char *string, const char *charToSearch);
/**
* Extract string between 2 characters
* This function return the string between 2 given characters
* @param string - The original string
* @param first - The first character
* @param last - The second character
* @return extracted string
*/
char *extractBetweenChar(const char *string, char first, char last);
/**
* Extract string between 2 indexes
* This function return the string between 2 given indexes
* @param string - The original string
* @param first - The first index
* @param last - The second index
* @return extracted string
*/
char *extractBetweenIndexes(const char *string, int first, int last);
/**
* Extract up to an index
* This function return the string until an index
* @param string - The original string
* @param last - The end index
* @return extracted string
*/
char *extractUpToIndex(const char *string, int last);
/**
* Check if there exist an operator outside of parenthesis
* @param string - String to scan
* @return result of the scan
*/
char operatorWithoutDepth(const char *string);
/**
* Find next operand in string
* This functions update to indexes to surround the next operand in a string
* @note If the end of the string is reached, both indexes will point to the end of the string ('\0')
* @param string - String to scan
* @param firstIndex - Index to place before next operand
* @param secondIndex - Index to place after next operand
*/
void nextOperator(const char *string, int *firstIndex, int *secondIndex);
/**
* Verify if the string only contain a number
* @param string - String to scan
* @return result of the scan
*/
char onlyContainValue(const char *string);
/**
* Verify if the string only contain a valid polynomial coefficient
* @param string - String to scan
* @return result of the scan
*/
char isValidPolynomial(const char *string);
/**
* Verify if everything is between parenthesis
* @note This function doesn't count whitespaces, if they are some outside of parenthesis it will not count them
* @param string - String to scan
* @return result of the scan
*/
char everythingIsBetweenParenthesis(const char *string);
/**
* Read a double in a string
* This function return a double read from a string
* @param string - The given string
* @param position - The position of the string where we start to read
* @return double read
*/
double readDoubleInString(const char *string, int *position);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// File interactions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* Print the content of a file in a buffer
* This function print the content of the file at the given link in the output buffer without modifying it
* @param link - Link of the file to read
* @param output - Buffer where the content while be outputted
*/
void printFileContent(const char *link, FILE *output);
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// Matrix interactions
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/**
* @struct StringMatrix
* Structure representing a matrix of any size but with values in string format
*/
typedef struct {
char *name;
char ***values; ///Elements of the matrix contained in a 2 dimensional array
int rows; ///Number of rows of the matrix
int columns; ///Number of columns matrix
} StringMatrix;
/**
* Create string matrix
* This function create a matrix with strings as values, this is used to handle matrix with variables
* @param nbRows - number of rows of the matrix
* @param nbColumns - number of columns of the matrix
* @return created string matrix
*/
StringMatrix newStringMatrix(int nbRows, int nbColumns);
/**
* Remove a row in a string matrix
* This function return a string matrix created by removing a row of a given string matrix
* @param M - The original string matrix
* @param rowIndex - The index of the row to remove
* @return string matrix created by removing a row
*/
StringMatrix removeSRow(StringMatrix M, int rowIndex);
/**
* Remove a column in a string matrix
* This function return a string matrix created by removing a column of a given matrix
* @param M - The original string matrix
* @param columnIndex - The index of the column to remove
* @return string matrix created by removing a column
*/
StringMatrix removeSColumn(StringMatrix M, int columnIndex);
/**
* Implement a variable
* This function add the variable in the diagonal to be used for P(lambda)
* @param M - The given string matrix
* @return string matrix with the variable X subtracted in the diagonal
*/
StringMatrix changeToPLambdaForm(StringMatrix M);
/**
* Determinant in string format
* This function output the determinant of a given matrix in string format
* @param M - The given string matrix
* @return determinant in string format
*/
char *detOfStringMatrix(StringMatrix M);
#endif //LINEARALGEBRA_STRINGINTERACTIONS_H