xref: /aosp_15_r20/external/icu/libicu/ndk_headers/unicode/parseerr.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 *   Copyright (C) 1999-2005, International Business Machines
6 *   Corporation and others.  All Rights Reserved.
7 **********************************************************************
8 *   Date        Name        Description
9 *   03/14/00    aliu        Creation.
10 *   06/27/00    aliu        Change from C++ class to C struct
11 **********************************************************************
12 */
13 #ifndef PARSEERR_H
14 #define PARSEERR_H
15 
16 #include "unicode/utypes.h"
17 
18 
19 /**
20  * @addtogroup icu4c ICU4C
21  * @{
22  * \file
23  * \brief C API: Parse Error Information
24  */
25 /**
26  * The capacity of the context strings in UParseError.
27  * \xrefitem stable "Stable" "Stable List" ICU 2.0
28  */
29 enum { U_PARSE_CONTEXT_LEN = 16 };
30 
31 /**
32  * A UParseError struct is used to returned detailed information about
33  * parsing errors.  It is used by ICU parsing engines that parse long
34  * rules, patterns, or programs, where the text being parsed is long
35  * enough that more information than a UErrorCode is needed to
36  * localize the error.
37  *
38  * <p>The line, offset, and context fields are optional; parsing
39  * engines may choose not to use to use them.
40  *
41  * <p>The preContext and postContext strings include some part of the
42  * context surrounding the error.  If the source text is "let for=7"
43  * and "for" is the error (e.g., because it is a reserved word), then
44  * some examples of what a parser might produce are the following:
45  *
46  * <pre>
47  * preContext   postContext
48  * ""           ""            The parser does not support context
49  * "let "       "=7"          Pre- and post-context only
50  * "let "       "for=7"       Pre- and post-context and error text
51  * ""           "for"         Error text only
52  * </pre>
53  *
54  * <p>Examples of engines which use UParseError (or may use it in the
55  * future) are Transliterator, RuleBasedBreakIterator, and
56  * RegexPattern.
57  *
58  * \xrefitem stable "Stable" "Stable List" ICU 2.0
59  */
60 typedef struct UParseError {
61 
62     /**
63      * The line on which the error occurred.  If the parser uses this
64      * field, it sets it to the line number of the source text line on
65      * which the error appears, which will be a value >= 1.  If the
66      * parse does not support line numbers, the value will be <= 0.
67      * \xrefitem stable "Stable" "Stable List" ICU 2.0
68      */
69     int32_t        line;
70 
71     /**
72      * The character offset to the error.  If the line field is >= 1,
73      * then this is the offset from the start of the line.  Otherwise,
74      * this is the offset from the start of the text.  If the parser
75      * does not support this field, it will have a value < 0.
76      * \xrefitem stable "Stable" "Stable List" ICU 2.0
77      */
78     int32_t        offset;
79 
80     /**
81      * Textual context before the error.  Null-terminated.  The empty
82      * string if not supported by parser.
83      * \xrefitem stable "Stable" "Stable List" ICU 2.0
84      */
85     UChar          preContext[U_PARSE_CONTEXT_LEN];
86 
87     /**
88      * The error itself and/or textual context after the error.
89      * Null-terminated.  The empty string if not supported by parser.
90      * \xrefitem stable "Stable" "Stable List" ICU 2.0
91      */
92     UChar          postContext[U_PARSE_CONTEXT_LEN];
93 
94 } UParseError;
95 
96 #endif
97 
98 /** @} */ // addtogroup
99