/***************************************************************************
                            KRegExp.m -  description
                             -------------------
    begin                : Fri Mar  8 13:55:08 2002
    copyright            : (C) 2000-2002 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Fri Mar  8 13:55:08 2002, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <kdec/kde_KRegExp.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/KRegExp.h>

@implementation  KRegExp

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- init
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KRegExp()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)_pattern _mode: (NSString *)_mode
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KRegExp1((char*) [_pattern cString], (char*) [_mode cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithText: (NSString *)_pattern 
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_KRegExp1((char*) [_pattern cString], "")];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			kde_del_KRegExp((kde_KRegExp *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) compile: (NSString *)_pattern _mode: (NSString *)_mode
{
	return (BOOL) kde_KRegExp_compile((kde_KRegExp *)[self qt], (char*) [_pattern cString], (char*) [_mode cString]);
}

- (BOOL) compile: (NSString *)_pattern 
{
	return (BOOL) kde_KRegExp_compile((kde_KRegExp *)[self qt], (char*) [_pattern cString], "");
}

- (BOOL) match: (NSString *)_string
{
	return (BOOL) kde_KRegExp_match((kde_KRegExp *)[self qt], (char*) [_string cString]);
}

- (NSString *) group: (int)_grp
{
	return (NSString *) [NSString stringWithCString: kde_KRegExp_group((kde_KRegExp *)[self qt], (int)_grp)];
}

- (int) groupStart: (int)_grp
{
	return (int) kde_KRegExp_groupStart((kde_KRegExp *)[self qt], (int)_grp);
}

- (int) groupEnd: (int)_grp
{
	return (int) kde_KRegExp_groupEnd((kde_KRegExp *)[self qt], (int)_grp);
}

@end
