[Half-Life AMXX] / include / regex.inc Repository:
ViewVC logotype

Diff of /include/regex.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1, Tue Oct 30 09:08:11 2007 UTC revision 17, Fri Nov 16 15:29:57 2007 UTC
# Line 26  Line 26 
26          REGEX_OK          REGEX_OK
27  };  };
28    
29  /* Return values:  /**
30     -2 = Matching error (error code stored in ret)   * Precompile a regular expression.  Use this if you intend on using the
31     -1 = Error in pattern (error message and offset # in error[] and ret)   * same expression multiple times.  Pass the regex handle returned here to
32      0 = No match   * regex_match_c to check for matches.
33     >1 = Id for getting more info (you must call regex_free() later on)   *
34          (also note that ret will contain the number of substrings found)   * @param pattern               The regular expression pattern.
35     * @param errcode               Error code encountered, if applicable.
36     * @param error         Error message encountered, if applicable.
37     * @param maxLen                Maximum string length of the error buffer.
38     * @param flags         General flags for the regular expression.
39     *                                              i = Ignore case
40     *                                              m = Multilines (affects ^ and $ so that they match
41     *                                                      the start/end of a line rather than matching the
42     *                                                      start/end of the string).
43     *                                              s = Single line (affects . so that it matches any character,
44     *                                                      even new line characters).
45     *                                              x = Pattern extension (ignore whitespace and # comments).
46     *
47     * @return                              -1 on error in the pattern, > valid regex handle (> 0) on success.
48     *
49     * @note                                This handle is automatically freed on map change.  However,
50     *                                              if you are completely done with it before then, you should
51     *                                              call regex_free on this handle.
52   */   */
53    native Regex:regex_compile(const pattern[], &ret, error[], maxLen, const flags[]="");
54    
55  native Regex:regex_match(const string[], const pattern[], &ret, error[], maxLen);  /**
56     * Matches a string against a pre-compiled regular expression pattern.
57     *
58     *
59     * @param pattern               The regular expression pattern.
60     * @param string                The string to check.
61     * @param ret                   Error code, if applicable, or number of results on success.
62     *
63     * @return                              -2 = Matching error (error code is stored in ret)
64     *                                               0 = No match.
65     *                                              >1 = Number of results.
66     *
67     * @note                                You should free the returned handle (with regex_free())
68     *                                              when you are done with this pattern.
69     *
70     * @note                                Use the regex handle passed to this function to extract
71     *                                              matches with regex_substr().
72     */
73    native regex_match_c(const string[], Regex:pattern, &ret);
74    
75    /**
76     * Matches a string against a regular expression pattern.
77     *
78     * @note                                If you intend on using the same regular expression pattern
79     *                                              multiple times, consider using regex_compile and regex_match_c
80     *                                              instead of making this function reparse the expression each time.
81     *
82     * @param string                The string to check.
83     * @param pattern               The regular expression pattern.
84     * @param ret                   Error code, or result state of the match.
85     * @param error         Error message, if applicable.
86     * @param maxLen                Maximum length of the error buffer.
87     * @param flags         General flags for the regular expression.
88     *                                              i = Ignore case
89     *                                              m = Multilines (affects ^ and $ so that they match
90     *                                                      the start/end of a line rather than matching the
91     *                                                      start/end of the string).
92     *                                              s = Single line (affects . so that it matches any character,
93     *                                                      even new line characters).
94     *                                              x = Pattern extension (ignore whitespace and # comments).
95     *
96     * @return                              -2 = Matching error (error code is stored in ret)
97     *                                              -1 = Error in pattern (error message and offset # in error and ret)
98     *                                               0 = No match.
99     *                                              >1 = Handle for getting more information (via regex_substr)
100     *
101     * @note                                Flags only exist in amxmodx 1.8 and later.
102     * @note                                You should free the returned handle (with regex_free())
103     *                                              when you are done extracting all of the substrings.
104     */
105    native Regex:regex_match(const string[], const pattern[], &ret, error[], maxLen, const flags[] = "");
106    
107  /* Returns a matched substring from a regex handle  /**
108   * substring ids start at 0 and end at ret-1, where ret is from the above function   * Returns a matched substring from a regex handle.
109     * Substring ids start at 0 and end at ret-1, where ret is from the corresponding
110     * regex_match or regex_match_c function call.
111     *
112     * @param id                    The regex handle to extract data from.
113     * @param str_id                The index of the expression to get - starts at 0, and ends at ret - 1.
114     * @param buffer                The buffer to set to the matching substring.
115     * @param maxLen                The maximum string length of the buffer.
116     *
117   */   */
118  native regex_substr(Regex:id, str_id, buffer[], maxLen);  native regex_substr(Regex:id, str_id, buffer[], maxLen);
119    
120  /* Frees the memory associated with a regex results and sets the handle to 0.  /**
121   * You must do this if the handle >=1, once you're done.   * Frees the memory associated with a regex result, and sets the handle to 0.
122     * This must be called on all results from regex_match() when you are done extracting
123     * the results with regex_substr().
124     * The results of regex_compile() (and subsequently, regex_match_c()) only need to be freed
125     * when you are done using the pattern.
126     *
127     *
128     * @param id                    The regex handle to free.
129     *
130     * @noreturn
131     *
132     * @note                                Do not use the handle again after freeing it!
133   */   */
134  native regex_free(&Regex:id);  native regex_free(&Regex:id);

Legend:
Removed from v.1  
changed lines
  Added in v.17

Contact
ViewVC Help
Powered by ViewVC 1.0.4