xref: /aosp_15_r20/external/icu/libandroidicu/include/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  * \file
21*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Parse Error Information
22*0e209d39SAndroid Build Coastguard Worker  */
23*0e209d39SAndroid Build Coastguard Worker /**
24*0e209d39SAndroid Build Coastguard Worker  * The capacity of the context strings in UParseError.
25*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
26*0e209d39SAndroid Build Coastguard Worker  */
27*0e209d39SAndroid Build Coastguard Worker enum { U_PARSE_CONTEXT_LEN = 16 };
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker /**
30*0e209d39SAndroid Build Coastguard Worker  * A UParseError struct is used to returned detailed information about
31*0e209d39SAndroid Build Coastguard Worker  * parsing errors.  It is used by ICU parsing engines that parse long
32*0e209d39SAndroid Build Coastguard Worker  * rules, patterns, or programs, where the text being parsed is long
33*0e209d39SAndroid Build Coastguard Worker  * enough that more information than a UErrorCode is needed to
34*0e209d39SAndroid Build Coastguard Worker  * localize the error.
35*0e209d39SAndroid Build Coastguard Worker  *
36*0e209d39SAndroid Build Coastguard Worker  * <p>The line, offset, and context fields are optional; parsing
37*0e209d39SAndroid Build Coastguard Worker  * engines may choose not to use to use them.
38*0e209d39SAndroid Build Coastguard Worker  *
39*0e209d39SAndroid Build Coastguard Worker  * <p>The preContext and postContext strings include some part of the
40*0e209d39SAndroid Build Coastguard Worker  * context surrounding the error.  If the source text is "let for=7"
41*0e209d39SAndroid Build Coastguard Worker  * and "for" is the error (e.g., because it is a reserved word), then
42*0e209d39SAndroid Build Coastguard Worker  * some examples of what a parser might produce are the following:
43*0e209d39SAndroid Build Coastguard Worker  *
44*0e209d39SAndroid Build Coastguard Worker  * <pre>
45*0e209d39SAndroid Build Coastguard Worker  * preContext   postContext
46*0e209d39SAndroid Build Coastguard Worker  * ""           ""            The parser does not support context
47*0e209d39SAndroid Build Coastguard Worker  * "let "       "=7"          Pre- and post-context only
48*0e209d39SAndroid Build Coastguard Worker  * "let "       "for=7"       Pre- and post-context and error text
49*0e209d39SAndroid Build Coastguard Worker  * ""           "for"         Error text only
50*0e209d39SAndroid Build Coastguard Worker  * </pre>
51*0e209d39SAndroid Build Coastguard Worker  *
52*0e209d39SAndroid Build Coastguard Worker  * <p>Examples of engines which use UParseError (or may use it in the
53*0e209d39SAndroid Build Coastguard Worker  * future) are Transliterator, RuleBasedBreakIterator, and
54*0e209d39SAndroid Build Coastguard Worker  * RegexPattern.
55*0e209d39SAndroid Build Coastguard Worker  *
56*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
57*0e209d39SAndroid Build Coastguard Worker  */
58*0e209d39SAndroid Build Coastguard Worker typedef struct UParseError {
59*0e209d39SAndroid Build Coastguard Worker 
60*0e209d39SAndroid Build Coastguard Worker     /**
61*0e209d39SAndroid Build Coastguard Worker      * The line on which the error occurred.  If the parser uses this
62*0e209d39SAndroid Build Coastguard Worker      * field, it sets it to the line number of the source text line on
63*0e209d39SAndroid Build Coastguard Worker      * which the error appears, which will be a value >= 1.  If the
64*0e209d39SAndroid Build Coastguard Worker      * parse does not support line numbers, the value will be <= 0.
65*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
66*0e209d39SAndroid Build Coastguard Worker      */
67*0e209d39SAndroid Build Coastguard Worker     int32_t        line;
68*0e209d39SAndroid Build Coastguard Worker 
69*0e209d39SAndroid Build Coastguard Worker     /**
70*0e209d39SAndroid Build Coastguard Worker      * The character offset to the error.  If the line field is >= 1,
71*0e209d39SAndroid Build Coastguard Worker      * then this is the offset from the start of the line.  Otherwise,
72*0e209d39SAndroid Build Coastguard Worker      * this is the offset from the start of the text.  If the parser
73*0e209d39SAndroid Build Coastguard Worker      * does not support this field, it will have a value < 0.
74*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
75*0e209d39SAndroid Build Coastguard Worker      */
76*0e209d39SAndroid Build Coastguard Worker     int32_t        offset;
77*0e209d39SAndroid Build Coastguard Worker 
78*0e209d39SAndroid Build Coastguard Worker     /**
79*0e209d39SAndroid Build Coastguard Worker      * Textual context before the error.  Null-terminated.  The empty
80*0e209d39SAndroid Build Coastguard Worker      * string if not supported by parser.
81*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
82*0e209d39SAndroid Build Coastguard Worker      */
83*0e209d39SAndroid Build Coastguard Worker     UChar          preContext[U_PARSE_CONTEXT_LEN];
84*0e209d39SAndroid Build Coastguard Worker 
85*0e209d39SAndroid Build Coastguard Worker     /**
86*0e209d39SAndroid Build Coastguard Worker      * The error itself and/or textual context after the error.
87*0e209d39SAndroid Build Coastguard Worker      * Null-terminated.  The empty string if not supported by parser.
88*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 2.0
89*0e209d39SAndroid Build Coastguard Worker      */
90*0e209d39SAndroid Build Coastguard Worker     UChar          postContext[U_PARSE_CONTEXT_LEN];
91*0e209d39SAndroid Build Coastguard Worker 
92*0e209d39SAndroid Build Coastguard Worker } UParseError;
93*0e209d39SAndroid Build Coastguard Worker 
94*0e209d39SAndroid Build Coastguard Worker #endif
95