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