// Class: lime.text.unifill._Utf16.Utf16Impl

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../../../hxClasses_stub").default;
var $import = require("./../../../../import_stub").default;
function lime_text_unifill_Unicode() {return require("./../../../../lime/text/unifill/Unicode");}
function js__$Boot_HaxeError() {return require("./../../../../js/_Boot/HaxeError");}
function lime_text_unifill_InvalidCodeUnitSequence() {return require("./../../../../lime/text/unifill/InvalidCodeUnitSequence");}

// Constructor

var Utf16Impl = function(){}

// Meta

Utf16Impl.__name__ = ["lime","text","unifill","_Utf16","Utf16Impl"];
Utf16Impl.prototype = {
	
};
Utf16Impl.prototype.__class__ = Utf16Impl.prototype.constructor = $hxClasses["lime.text.unifill._Utf16.Utf16Impl"] = Utf16Impl;

// Init



// Statics

Utf16Impl.code_point_width = function(c) {
	if(!(lime_text_unifill_Unicode().default).isHighSurrogate(c)) {
		return 1;
	} else {
		return 2;
	}
}
Utf16Impl.find_prev_code_point = function(accessor,index) {
	var c = accessor(index - 1);
	if(!(lime_text_unifill_Unicode().default).isLowSurrogate(c)) {
		return 1;
	} else {
		return 2;
	}
}
Utf16Impl.encode_code_point = function(addUnit,codePoint) {
	if(codePoint <= 65535) {
		addUnit(codePoint);
	} else {
		addUnit((lime_text_unifill_Unicode().default).encodeHighSurrogate(codePoint));
		addUnit((lime_text_unifill_Unicode().default).encodeLowSurrogate(codePoint));
	}
}
Utf16Impl.decode_code_point = function(len,accessor,index) {
	if(index < 0 || len <= index) {
		throw new (js__$Boot_HaxeError().default)(new (lime_text_unifill_InvalidCodeUnitSequence().default)(index));
	}
	var hi = accessor(index);
	if((lime_text_unifill_Unicode().default).isHighSurrogate(hi)) {
		if(index + 1 < 0 || len <= index + 1) {
			throw new (js__$Boot_HaxeError().default)(new (lime_text_unifill_InvalidCodeUnitSequence().default)(index));
		}
		var lo = accessor(index + 1);
		if((lime_text_unifill_Unicode().default).isLowSurrogate(lo)) {
			return (lime_text_unifill_Unicode().default).decodeSurrogate(hi,lo);
		} else {
			throw new (js__$Boot_HaxeError().default)(new (lime_text_unifill_InvalidCodeUnitSequence().default)(index));
		}
	} else if((lime_text_unifill_Unicode().default).isLowSurrogate(hi)) {
		throw new (js__$Boot_HaxeError().default)(new (lime_text_unifill_InvalidCodeUnitSequence().default)(index));
	} else {
		return hi;
	}
}


// Export

exports.default = Utf16Impl;