Blame Detector.xs

Packit 67f6e7
//  ***** BEGIN LICENSE BLOCK *****
Packit 67f6e7
//  Version: MPL 1.1/GPL 2.0/LGPL 2.1
Packit 67f6e7
// 
Packit 67f6e7
//  The contents of this file are subject to the Mozilla Public License Version
Packit 67f6e7
//  1.1 (the "License"); you may not use this file except in compliance with
Packit 67f6e7
//  the License. You may obtain a copy of the License at
Packit 67f6e7
//  http://www.mozilla.org/MPL/
Packit 67f6e7
// 
Packit 67f6e7
//  Software distributed under the License is distributed on an "AS IS" basis,
Packit 67f6e7
//  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
Packit 67f6e7
//  for the specific language governing rights and limitations under the
Packit 67f6e7
//  License.
Packit 67f6e7
// 
Packit 67f6e7
//  The Original Code is Encode::Detect wrapper
Packit 67f6e7
// 
Packit 67f6e7
//  The Initial Developer of the Original Code is
Packit 67f6e7
//  Proofpoint, Inc.
Packit 67f6e7
//  Portions created by the Initial Developer are Copyright (C) 2005
Packit 67f6e7
//  the Initial Developer. All Rights Reserved.
Packit 67f6e7
// 
Packit 67f6e7
//  Contributor(s):
Packit 67f6e7
// 
Packit 67f6e7
//  Alternatively, the contents of this file may be used under the terms of
Packit 67f6e7
//  either the GNU General Public License Version 2 or later (the "GPL"), or
Packit 67f6e7
//  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
Packit 67f6e7
//  in which case the provisions of the GPL or the LGPL are applicable instead
Packit 67f6e7
//  of those above. If you wish to allow use of your version of this file only
Packit 67f6e7
//  under the terms of either the GPL or the LGPL, and not to allow others to
Packit 67f6e7
//  use your version of this file under the terms of the MPL, indicate your
Packit 67f6e7
//  decision by deleting the provisions above and replace them with the notice
Packit 67f6e7
//  and other provisions required by the GPL or the LGPL. If you do not delete
Packit 67f6e7
//  the provisions above, a recipient may use your version of this file under
Packit 67f6e7
//  the terms of any one of the MPL, the GPL or the LGPL.
Packit 67f6e7
// 
Packit 67f6e7
//  ***** END LICENSE BLOCK *****
Packit 67f6e7
Packit 67f6e7
extern "C" {
Packit 67f6e7
#define PERL_NO_GET_CONTEXT     /* we want efficiency */
Packit 67f6e7
#include "EXTERN.h"
Packit 67f6e7
#include "perl.h"
Packit 67f6e7
Packit 67f6e7
// work around perlbug #39634
Packit 67f6e7
#if __GNUC__ == 3 && __GNUC_MINOR__ <= 3
Packit 67f6e7
#undef HASATTRIBUTE_UNUSED
Packit 67f6e7
#endif
Packit 67f6e7
Packit 67f6e7
#include "XSUB.h"
Packit 67f6e7
}
Packit 67f6e7
Packit 67f6e7
#include "nscore.h"
Packit 67f6e7
#include "nsUniversalDetector.h"
Packit 67f6e7
Packit 67f6e7
class Detector: public nsUniversalDetector {
Packit 67f6e7
    public:
Packit 67f6e7
	Detector() {};
Packit 67f6e7
	virtual ~Detector() {}
Packit 67f6e7
	const char *getresult() { return mDetectedCharset; }
Packit 67f6e7
	virtual void Reset() { this->nsUniversalDetector::Reset(); }
Packit 67f6e7
    protected:
Packit 67f6e7
	virtual void Report(const char* aCharset) { mDetectedCharset = aCharset; }
Packit 67f6e7
};
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
MODULE = Encode::Detect::Detector		PACKAGE = Encode::Detect::Detector
Packit 67f6e7
PROTOTYPES: ENABLE
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
Detector *
Packit 67f6e7
Detector::new()
Packit 67f6e7
Packit 67f6e7
void
Packit 67f6e7
Detector::DESTROY()
Packit 67f6e7
Packit 67f6e7
int
Packit 67f6e7
Detector::handle(SV *buf)
Packit 67f6e7
    CODE:
Packit 67f6e7
	STRLEN len;
Packit 67f6e7
	char *ptr = SvPV(buf, len);
Packit 67f6e7
	RETVAL = THIS->HandleData(ptr, len);
Packit 67f6e7
    OUTPUT:
Packit 67f6e7
	RETVAL
Packit 67f6e7
Packit 67f6e7
void
Packit 67f6e7
Detector::eof()
Packit 67f6e7
    CODE:
Packit 67f6e7
	THIS->DataEnd();
Packit 67f6e7
Packit 67f6e7
void
Packit 67f6e7
Detector::reset()
Packit 67f6e7
    CODE:
Packit 67f6e7
	THIS->Reset();
Packit 67f6e7
Packit 67f6e7
const char *
Packit 67f6e7
Detector::getresult()
Packit 67f6e7
    CODE:
Packit 67f6e7
	RETVAL = THIS->getresult();
Packit 67f6e7
    OUTPUT:
Packit 67f6e7
	RETVAL
Packit 67f6e7
Packit 67f6e7
Packit 67f6e7
const char *
Packit 67f6e7
detect(buf)
Packit 67f6e7
	SV *buf
Packit 67f6e7
    CODE:
Packit 67f6e7
	STRLEN len;
Packit 67f6e7
	char *ptr = SvPV(buf, len);
Packit 67f6e7
Packit 67f6e7
	Detector *det = new Detector;
Packit 67f6e7
	det->HandleData(ptr, len);
Packit 67f6e7
	det->DataEnd();
Packit 67f6e7
	RETVAL = det->getresult();
Packit 67f6e7
	delete det;
Packit 67f6e7
    OUTPUT:
Packit 67f6e7
        RETVAL
Packit 67f6e7