home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kregexp.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  3.9 KB  |  130 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (c) 1999 Torben Weis <weis@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef __kregexp_h__
  19. #define __kregexp_h__
  20.  
  21. #include "kdelibs_export.h"
  22.  
  23. class KRegExpPrivate;
  24.  
  25. /**
  26.  * @deprecated
  27.  * Please use QRegExp instead.
  28.  *
  29.  * Regular expression (regexp) matching with back-references.
  30.  *
  31.  * This was implemented
  32.  * because QRegExp did not support back-references. It now does and
  33.  * is recommended over KRegExp because of the unicode support and the
  34.  * more powerful API.
  35.  *
  36.  * Back-references are parts of a regexp grouped with parentheses. If a
  37.  * string matches the regexp, you can access the text that matched each
  38.  * group with the group method. This is similar to regular expressions 
  39.  * in Perl.
  40.  *
  41.  * Example:
  42.  * \code
  43.  *  KRegExp ex( "([A-Za-z]+) (.+)" );
  44.  *  ex.match( "42 Torben Weis" );
  45.  *  kdDebug() << ex.group(0) << endl;
  46.  *  kdDebug() << ex.group(1) << endl;
  47.  *  kdDebug() << ex.group(2) << endl;
  48.  * \endcode
  49.  * Output:
  50.  * \code
  51.  *  Torben Weis
  52.  *  Torben
  53.  *  Weis
  54.  * \endcode
  55.  *
  56.  * Please notice that KRegExp does @em not support unicode.
  57.  *
  58.  * @author Torben Weis <weis@kde.org>
  59.  */
  60. class KDECORE_EXPORT KDE_DEPRECATED KRegExp
  61. {
  62. public:
  63.  
  64.   /**
  65.    * Creates a KRegExp object without a default pattern.
  66.    */
  67.   KRegExp();
  68.  
  69.   /**
  70.    * Creates a KRegExp object.
  71.    * @param _pattern    The regular expression to use for matches.
  72.    * @param _mode    If this is "i", case-insensitive matches will be
  73.    *             performed.
  74.    */
  75.   KRegExp( const char *_pattern, const char *_mode = "" );
  76.   ~KRegExp();
  77.  
  78.   /**
  79.    * Prepare a regular expression for subsequent matches.
  80.    * @param _pattern    The regular expression to use for matches.
  81.    * @param _mode    If this is "i", case-insensitive matches will be
  82.    *             performed.
  83.    * @return bool if successful.
  84.    */
  85.   bool compile( const char *_pattern, const char *_mode = "" );
  86.  
  87.   /**
  88.    * Match a string to the last supplied regexp.
  89.    * @param _string the string to match
  90.    * @return @p true on match, false otherwise.
  91.    */
  92.   bool match( const char *_string );
  93.  
  94.  
  95.   /**
  96.    * Returns a group from the match.
  97.    *
  98.    * @param _grp May be in the range [0..9]. If @p _grp is 0 then the complete
  99.    *             matched string is returned.
  100.    * @return a grouped substring. A substring may be empty.
  101.    *         In this case 0 is returned. Otherwise you may @em not
  102.    *         delete or modify the returned value. In addition the
  103.    *         returned value becomes invalid after the KRegExp instance
  104.    *         is deleted or after match() was called again.
  105.    */
  106.   const char *group( int _grp );
  107.  
  108.   /**
  109.    * The offset of the given group in the string.
  110.    * @param _grp May be in the range [0..9]. If @p _grp is 0 then the start offset
  111.    *             of the complete matched string is returned.
  112.    * @return The start offset of the grouped substring.
  113.    */
  114.   int groupStart( int _grp );
  115.   /**
  116.    * The offset of the given group's end in the string.
  117.    * @param _grp May be in the range [0..9]. If @p _grp is 0 then the end offset
  118.    *             of the complete matched string is returned.
  119.    * @return The end offset of the grouped substring. The "end offset" is the first
  120.    *         character after the string.
  121.    */
  122.   int groupEnd( int _grp );
  123.  
  124. private:
  125.   KRegExpPrivate *m_pPrivate;
  126. };
  127.  
  128.  
  129. #endif
  130.