MPLABĀ® Harmony Graphics Suite
legato_stringutils.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
23 
24 /*******************************************************************************
25  Module for Microchip Graphics Library - Legato User Interface Library
26 
27  Company:
28  Microchip Technology Inc.
29 
30  File Name:
31  legato_stringutils.h
32 
33  Summary:
34 
35 
36  Description:
37  This module implements various string utility functions.
38 *******************************************************************************/
45 #ifndef LE_STRINGUTILS_H
46 #define LE_STRINGUTILS_H
47 
49 
50 // *****************************************************************************
67 LIB_EXPORT uint32_t leStringUtils_FromCStr(const char* str,
68  leChar* buf,
69  uint32_t size);
70 
71 // *****************************************************************************
88 LIB_EXPORT uint32_t leStringUtils_ToCStr(const leChar* str,
89  uint32_t strSize,
90  char* buf,
91  uint32_t bufSize);
92 
93 // *****************************************************************************
106 LIB_EXPORT leResult leStringUtils_GetRect(const leChar* str,
107  uint32_t size,
108  const leFont* font,
109  leRect* rect);
110 
111 // *****************************************************************************
126 LIB_EXPORT leResult leStringUtils_GetRectCStr(const char* str,
127  const leFont* font,
128  leRect* rect);
129 
130 // *****************************************************************************
144 LIB_EXPORT uint32_t leStringUtils_GetLineCount(const leChar* str,
145  uint32_t size);
146 
147 // *****************************************************************************
158 LIB_EXPORT uint32_t leStringUtils_GetLineCountCStr(const char* str);
159 
160 // *****************************************************************************
178 LIB_EXPORT leResult leStringUtils_GetLineIndices(const leChar* str,
179  uint32_t size,
180  uint32_t line,
181  uint32_t* start,
182  uint32_t* end);
183 
184 // *****************************************************************************
185 /* Function:
186  leResult leStringUtils_GetLineIndicesCStr(const char* str,
187  uint32_t line,
188  uint32_t* start,
189  uint32_t* end)
190 
191  Summary:
192 
193 
194  Description:
195  Gets the line indices for a C-style string
196 
197  Parameters:
198  const char* str - the source C-string to aGets the line indices for a C-style stringnalyze
199  uint32_t line - the line index to query
200  uint32_t* start - will contain the start index of the line
201  uint32_t* end - will contain the end index of the line
202 
203  Remarks:
204 
205  Returns:
206  leResult - the result of the operation
207 */
218 LIB_EXPORT leResult leStringUtils_GetLineIndicesCStr(const char* str,
219  uint32_t line,
220  uint32_t* start,
221  uint32_t* end);
222 
223 // *****************************************************************************
224 /* Function:
225  leResult leStringUtils_GetLineRect(const leChar* str,
226  uint32_t size,
227  const leFont* font,
228  uint32_t line,
229  leRect* rect)
230 
231  Summary:
232  Gets the line bounding rectangle for a leChar style string
233 
234  Description:
235  Gets the line bounding rectangle for a leChar style string
236 
237  Parameters:
238  const leChar* str - the source leChar string
239  uint32_t size - the size of the input buffer in code points
240  const leFont* font - the font to reference
241  uint32_t line - the line index to reference
242  leRect* rect - will contain the line bounding rectangle
243 
244  Remarks:
245 
246  Returns:
247  leResult - the result of the operation
248 */
259 LIB_EXPORT leResult leStringUtils_GetLineRect(const leChar* str,
260  uint32_t size,
261  const leFont* font,
262  uint32_t line,
263  leRect* rect);
264 
265 // *****************************************************************************
266 /* Function:
267  leResult leStringUtils_GetLineRectCStr(const char* str,
268  const leFont* font,
269  uint32_t line,
270  leRect* rect)
271 
272  Summary:
273  Gets the line bounding rectangle for a C-style string
274 
275  Description:
276  Gets the line bounding rectangle for a C-style string
277 
278  Parameters:
279  const char* str - the source C string
280  const leFont* font - the font to reference
281  uint32_t line - the line index to reference
282  leRect* rect - will contain the line bounding rectangle
283 
284  Remarks:
285 
286  Returns:
287  leResult - the result of the operation
288 */
300 LIB_EXPORT leResult leStringUtils_GetLineRectCStr(const char* str,
301  const leFont* font,
302  uint32_t line,
303  leRect* rect);
304 
305 // *****************************************************************************
306 /* Function:
307  leResult leStringUtils_GetCharRect(const leChar* str,
308  uint32_t size,
309  const leFont* font,
310  uint32_t charIdx,
311  leRect* rect)
312 
313  Summary:
314  Gets a glyph bounding rectangle for a leChar style string
315 
316  Description:
317  Gets a glyph bounding rectangle for a leChar style string
318 
319  Parameters:
320  const leChar* str - the source leChar string
321  uint32_t size - the size of the input buffer in code points
322  const leFont* font - the font to reference
323  uint32_t charIdx - the char index to reference
324  leRect* rect - will contain the glyph bounding rectangle
325 
326  Remarks:
327 
328  Returns:
329  leResult - the result of the operation
330 */
341 LIB_EXPORT leResult leStringUtils_GetCharRect(const leChar* str,
342  uint32_t size,
343  const leFont* font,
344  uint32_t charIdx,
345  leRect* rect);
346 
347 // *****************************************************************************
348 /* Function:
349  leResult leStringUtils_GetCharRectCStr(const char* str,
350  const leFont* font,
351  uint32_t charIdx,
352  leRect* rect)
353 
354  Summary:
355  Gets a glyph bounding rectangle for a C-style string
356 
357  Description:
358  Gets a glyph bounding rectangle for a C-style string
359 
360  Parameters:
361  const char* str - the source C string
362  const leFont* font - the font to reference
363  uint32_t charIdx - the char index to reference
364  leRect* rect - will contain the glyph bounding rectangle
365 
366  Remarks:
367 
368  Returns:
369  leResult - the result of the operation
370 */
381 LIB_EXPORT leResult leStringUtils_GetCharRectCStr(const char* str,
382  const leFont* font,
383  uint32_t charIdx,
384  leRect* rect);
385 
386 // *****************************************************************************
387 /* Function:
388  leResult leStringUtils_GetCharIndexAtPoint(const leChar* str,
389  uint32_t size,
390  const leFont* font,
391  const lePoint pt,
392  uint32_t* charIdx)
393 
394  Summary:
395  Gets the glyph at a point inside a leChar string bounding rectangle
396 
397  Description:
398  Gets the glyph at a point inside a leChar string bounding rectangle
399 
400  Parameters:
401  const leChar* str - the source leChar string
402  uint32_t size - the size of the input buffer in code points
403  const leFont* font - the font to reference
404  const lePoint pt - the point to query with
405  uint32_t* charIdx - will contain the index of the char at pt
406 
407  Remarks:
408 
409  Returns:
410  leResult - the result of the operation
411 */
422 LIB_EXPORT leResult leStringUtils_GetCharIndexAtPoint(const leChar* str,
423  uint32_t size,
424  const leFont* font,
425  const lePoint pt,
426  uint32_t* charIdx);
427 
428 // *****************************************************************************
429 /* Function:
430  leResult leStringUtils_GetCharIndexAtPointCStr(const char* str,
431  const leFont* font,
432  const lePoint pt,
433  uint32_t* charIdx)
434 
435  Summary:
436  Gets the glyph at a point inside a C-style string bounding rectangle
437 
438  Description:
439  Gets the glyph at a point inside a C-style string bounding rectangle
440 
441  Parameters:
442  const char* str - the source C string
443  const leFont* font - the font to reference
444  const lePoint pt - the point to query with
445  uint32_t* charIdx - will contain the index of the char at pt
446 
447  Remarks:
448 
449  Returns:
450  leResult - the result of the operation
451 */
461 LIB_EXPORT leResult leStringUtils_GetCharIndexAtPointCStr(const char* str,
462  const leFont* font,
463  const lePoint pt,
464  uint32_t* charIdx);
465 
466 // *****************************************************************************
467 /* Function:
468  leResult leDecodeCodePoint(uint32_t encoding,
469  uint8_t* data,
470  uint32_t max,
471  uint32_t* codePoint,
472  uint32_t* offset)
473 
474  Summary:
475  Given an encoded codepoint (ASCII, UTF-8, or UTF-16) returns the actual
476  codepoint
477 
478  Description:
479  Given an encoded codepoint (ASCII, UTF-8, or UTF-16) returns the actual
480  codepoint
481 
482  Parameters:
483  uint32_t encoding - the encoding of the value
484  uint8_t* data - the data to decode
485  uint32_t max - the size of the data buffer
486  uint32_t* codePoint - will contain the decoded code point
487  uint32_t* offset - will contain the offset in the buffer after the decode
488  point
489 
490  Remarks:
491 
492  Returns:
493  leResult - the result of the operation
494 */
506 LIB_EXPORT leResult leDecodeCodePoint(uint32_t encoding,
507  uint8_t* data,
508  uint32_t max,
509  uint32_t* codePoint,
510  uint32_t* offset);
511 
512 #endif /* LE_STRINGUTILS_H */
leStringUtils_ToCStr
LIB_EXPORT uint32_t leStringUtils_ToCStr(const leChar *str, uint32_t strSize, char *buf, uint32_t bufSize)
Convert leChar buffer to C-style string.
Definition: legato_stringutils.c:58
leResult
leResult
This enum represents function call results.
Definition: legato_common.h:134
leRect
This struct represents a rectangle.
Definition: legato_common.h:405
leStringUtils_GetRect
LIB_EXPORT leResult leStringUtils_GetRect(const leChar *str, uint32_t size, const leFont *font, leRect *rect)
Get bounding rectangle for a leChar style string.
Definition: legato_stringutils.c:86
leStringUtils_FromCStr
LIB_EXPORT uint32_t leStringUtils_FromCStr(const char *str, leChar *buf, uint32_t size)
Convert c-style string to leChar.
Definition: legato_stringutils.c:36
leStringUtils_GetCharRectCStr
LIB_EXPORT leResult leStringUtils_GetCharRectCStr(const char *str, const leFont *font, uint32_t charIdx, leRect *rect)
Gets a glyph bounding rectangle for a C-style string.
Definition: legato_stringutils.c:439
leStringUtils_GetLineRectCStr
LIB_EXPORT leResult leStringUtils_GetLineRectCStr(const char *str, const leFont *font, uint32_t line, leRect *rect)
Gets the line bounding rectangle for a C-style string.
Definition: legato_stringutils.c:347
leStringUtils_GetLineCountCStr
LIB_EXPORT uint32_t leStringUtils_GetLineCountCStr(const char *str)
Get line count for a C-style string.
Definition: legato_stringutils.c:194
leFont
This struct represents a font object.
Definition: legato_font.h:136
leRasterFont
This struct represents a rasterized font object.
Definition: legato_font.h:167
leFontGlyph
This struct represents a font glyph.
Definition: legato_font.h:90
leStringUtils_GetLineCount
LIB_EXPORT uint32_t leStringUtils_GetLineCount(const leChar *str, uint32_t size)
Get line count for a leChar style string.
Definition: legato_stringutils.c:172
length
virtual uint32_t length(const leString *_this)
Get length of the string.
leRectContainsPoint
LIB_EXPORT leBool leRectContainsPoint(const leRect *rect, const lePoint *point)
Determines if a point is inside a rectangle.
Definition: legato_rect.c:31
legato_string.h
Fixed string functions and definitions.
leFont_GetGlyphInfo
leResult leFont_GetGlyphInfo(const leFont *fnt, uint32_t codepoint, leFontGlyph *glyph)
Get glyph info.
Definition: legato_font.c:171
legato_stringutils.h
String utility functions and definitions.
legato_rect.h
Rectangle functions and definitions.
leStringUtils_GetLineIndices
LIB_EXPORT leResult leStringUtils_GetLineIndices(const leChar *str, uint32_t size, uint32_t line, uint32_t *start, uint32_t *end)
Get line indices for a leChar style string.
Definition: legato_stringutils.c:221
leStringUtils_GetCharRect
LIB_EXPORT leResult leStringUtils_GetCharRect(const leChar *str, uint32_t size, const leFont *font, uint32_t charIdx, leRect *rect)
Gets a glyph bounding rectangle for a leChar style string.
Definition: legato_stringutils.c:393
leStringUtils_GetLineIndicesCStr
LIB_EXPORT leResult leStringUtils_GetLineIndicesCStr(const char *str, uint32_t line, uint32_t *start, uint32_t *end)
Gets the line indices for a C-style string.
Definition: legato_stringutils.c:262
leStringUtils_GetLineRect
LIB_EXPORT leResult leStringUtils_GetLineRect(const leChar *str, uint32_t size, const leFont *font, uint32_t line, leRect *rect)
Gets the line bounding rectangle for a leChar style string.
Definition: legato_stringutils.c:305
leChar
uint16_t leChar
This typedef represents Legato character.
Definition: legato_common.h:424
LE_TRUE
@ LE_TRUE
Definition: legato_common.h:159
leStringUtils_GetRectCStr
LIB_EXPORT leResult leStringUtils_GetRectCStr(const char *str, const leFont *font, leRect *rect)
Gets the bounding rectangle for a C-style string.
Definition: legato_stringutils.c:128
lePoint
This structure represents a integer Cartesian point.
Definition: legato_common.h:357