HomeAut
string.h
1 /*
2  * string.h
3  *
4  * Author: Vizi Gábor
5  * E-mail: vizi.gabor90@gmail.com
6  * Function: string manipulation functions
7  * Target: STM32Fx
8  * Version: v4
9  * Last modified: 2016.09.28
10  */
11 
12 #ifndef STRING_H_
13 #define STRING_H_
14 
15 
16 /*------------------------------------------------------------------------------
17  * Includes
18  *----------------------------------------------------------------------------*/
19 
20 #include "include.h"
21 
22 #include <stdbool.h> // For bool
23 
24 #include <stdarg.h> // For "..." parameters in uprintf function
25 
26 #include "communication.h"
27 
28 
29 /*------------------------------------------------------------------------------
30  * Macros & definitions
31  *----------------------------------------------------------------------------*/
32 
33 
34 
35 /*------------------------------------------------------------------------------
36  * Type definitions
37  *----------------------------------------------------------------------------*/
38 
39 
40 
41 /*------------------------------------------------------------------------------
42  * Global variables
43  *----------------------------------------------------------------------------*/
44 
45 
46 
47 /*------------------------------------------------------------------------------
48  * Global function declarations
49  *----------------------------------------------------------------------------*/
50 
51 // Decimal --> String converters
52 uint8_t SignedDecimalToString(int32_t value, char *str);
53 uint8_t UnsignedDecimalToString(uint32_t value, char *str);
54 uint8_t UnsignedDecimalLength(uint32_t value);
55 uint8_t UnsignedDecimalToStringFill(uint32_t value, char *str,
56  uint8_t fillLength, char fillCharacter);
57 uint8_t SignedDecimalToStringFill(int32_t value, char *str,
58  uint8_t fillLength, char fillCharacter);
59 
60 // Num -> Binary String converter
61 uint8_t DecimalToBinaryString(uint32_t value, char *str, uint8_t maxLength);
62 
63 // Hexadecimal --> String converters
64 uint8_t DecimalToHexaString(uint32_t value, char *str, uint8_t length);
65 uint8_t ByteToHexaString(uint8_t byte, char *str);
66 char HexToHexChar(uint8_t octet);
67 
68 // Float --> String converter
69 uint8_t FloatToString(float value, char *str,
70  uint8_t integerLength, uint8_t fractionLength);
71 
72 // String checkers
73 bool IsHexChar(const char c);
74 bool IsDecimalChar(const char c);
75 
76 uint8_t StringIsHexadecimalString(const char *str);
77 uint8_t StringIsUnsignedDecimalString(const char *str);
78 uint8_t StringIsSignedDecimalString(const char *str);
79 
80 // BinaryString --> Integer converter
81 bool StringBinaryToNum(const char *str, uint32_t *num);
82 
83 // HexString --> Integer converters
84 bool HexCharToHex(const char c, uint8_t *hexValue);
85 bool StringByteToNum(const char *str, uint8_t *byte);
86 bool StringHexToNum(const char *str, uint32_t *hexValue);
87 
88 // Num string --> Integer converters
89 uint8_t DecimalCharToNum(char c);
90 bool StringToUnsignedDecimalNum(const char *str, uint32_t *value);
91 bool StringToSignedDecimalNum(const char *str, int32_t *value);
92 
93 // String --> Float converter
94 bool StringToFloat(const char *str, float *Num);
95 
96 // Standard string functions:
97 uint8_t StringLength(const char *str);
98 uint8_t StrCmp(const char * str1, const char *str2);
99 uint8_t StrCmpWithLength(const char * str1, const char *str2, uint8_t length);
100 uint8_t StrCpy(char *dest, const char *src);
101 uint8_t StrCpyFixLength(char *dest, const char *src, uint8_t length);
102 uint8_t StrCpyFixLengthWithFillCharacter(char *dest, const char *str,
103  uint8_t length, char fillChar);
104 uint8_t StrCpyMax(char *dest, const char *str, uint8_t maxLength);
105 uint8_t StrAppend(char *dest, const char *src);
106 
107 // Find & Separators
108 int16_t FindString(const char *str, const char *findString);
109 uint8_t STRING_Splitter(char *source, char delimiterChar,
110  char **separated, uint8_t parameterMaxCount);
111 
112 // Send functions
113 // !! IMPORTANT !! Send formatted string on USART !!
114 uint8_t string_printf(char *str, const char *format, va_list ap);
115 uint8_t usprintf(char *str, const char *format, ...);
116 uint8_t uprintf(const char *format, ...);
117 
118 // Unit test
119 void STRING_UnitTest(void);
120 
121 
122 
123 #endif /* STRING_H_ */