<commit_before>/*

Emglken Emscripten library
==========================

Copyright (c) 2017 <NAME>
MIT licenced
https://github.com/curiousdannii/emglken

*/

// These functions need GiDispa and Glk to be passed in the Module options object

var emglken = {

	window_from_ptr__postset: `var Glk=Module['Glk'],GiDispa=Module['GiDispa'];`,

	// Find JS objects from their id tags
	fileref_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'fileref', tag )
	},

	stream_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'stream', tag )
	},

	window_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'window', tag )
	},

	// Use the struct's first entry, the tag, to find the JS objects
	fileref_from_ptr: function( structptr )
	{
		return _fileref_from_id( getValue( structptr, 'i32' ) )
	},

	stream_from_ptr: function( streamptr )
	{
		return _stream_from_id( getValue( streamptr, 'i32' ) )
	},

	window_from_ptr: function( winptr )
	{
		return _window_from_id( getValue( winptr, 'i32' ) )
	},

	// Given a JS object, return its id tag
	fileref_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'fileref', tag )
	},

	stream_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'stream', tag )
	},

	window_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'window', tag )
	},

	// Functions for filling time and date structs
	glem_date_box_from_struct: function( dateptr )
	{
		for ( var datebox = new Glk.RefStruct(), i = 0; i < 8; i++ )
		{
			datebox.set_field( i, getValue( dateptr + ( 4 * i ), 'i32' ) )
		}
		return datebox
	},

	glem_date_box_to_struct: function( datebox, dateptr )
	{
		for ( var i = 0; i < 8; i++ )
		{
			setValue( dateptr + ( 4 * i ), datebox.get_field( i ), 'i32' )
		}
	},

	glem_time_box_from_struct: function( timeptr )
	{
		var timebox = new Glk.RefStruct()
		timebox.set_field( 0, getValue( timeptr, 'i32' ) )
		timebox.set_field( 1, getValue( timeptr + 4, 'i32' ) >>> 0 )
		timebox.set_field( 2, getValue( timeptr + 8, 'i32' ) )
		return timebox
	},

	glem_time_box_to_struct: function( timebox, timeptr )
	{
		for ( var i = 0; i < 3; i++ )
		{
			setValue( timeptr + ( 4 * i ), timebox.get_field( i ), 'i32' )
		}
	},

	// GlkApi's unicode functions are not TypedArray safe, so we must convert to normal arrays
	// See https://github.com/erkyrath/glkote/issues/27
	glk_buffer_canon_decompose_uni: function( bufaddr, len, numchars )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk.glk_buffer_canon_decompose_uni( buf, numchars )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_buffer_canon_normalize_uni: function( bufaddr, len, numchars )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk.glk_buffer_canon_normalize_uni( buf, numchars )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_buffer_to_lower_case_uni: function( bufaddr, len, numchars )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk.glk_buffer_to_lower_case_uni( buf, numchars )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_buffer_to_upper_case_uni: function( bufaddr, len, numchars )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk.glk_buffer_to_upper_case_uni( buf, numchars )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_buffer_to_title_case_uni: function( bufaddr, len, numchars, lowerrest )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk.glk_buffer_to_title_case_uni( buf, numchars, lowerrest )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_cancel_char_event: function( window )
	{<commit_msg>Apply some DRY to the unicode functions<commit_after>/*

Emglken Emscripten library
==========================

Copyright (c) 2017 <NAME>
MIT licenced
https://github.com/curiousdannii/emglken

*/

// These functions need GiDispa and Glk to be passed in the Module options object

var emglken = {

	window_from_ptr__postset: `var Glk=Module['Glk'],GiDispa=Module['GiDispa'];`,

	// Find JS objects from their id tags
	fileref_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'fileref', tag )
	},

	stream_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'stream', tag )
	},

	window_from_id: function( tag )
	{
		return GiDispa.class_obj_from_id( 'window', tag )
	},

	// Use the struct's first entry, the tag, to find the JS objects
	fileref_from_ptr: function( structptr )
	{
		return _fileref_from_id( getValue( structptr, 'i32' ) )
	},

	stream_from_ptr: function( streamptr )
	{
		return _stream_from_id( getValue( streamptr, 'i32' ) )
	},

	window_from_ptr: function( winptr )
	{
		return _window_from_id( getValue( winptr, 'i32' ) )
	},

	// Given a JS object, return its id tag
	fileref_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'fileref', tag )
	},

	stream_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'stream', tag )
	},

	window_to_id: function( tag )
	{
		return GiDispa.class_obj_to_id( 'window', tag )
	},

	// Functions for filling time and date structs
	glem_date_box_from_struct: function( dateptr )
	{
		for ( var datebox = new Glk.RefStruct(), i = 0; i < 8; i++ )
		{
			datebox.set_field( i, getValue( dateptr + ( 4 * i ), 'i32' ) )
		}
		return datebox
	},

	glem_date_box_to_struct: function( datebox, dateptr )
	{
		for ( var i = 0; i < 8; i++ )
		{
			setValue( dateptr + ( 4 * i ), datebox.get_field( i ), 'i32' )
		}
	},

	glem_time_box_from_struct: function( timeptr )
	{
		var timebox = new Glk.RefStruct()
		timebox.set_field( 0, getValue( timeptr, 'i32' ) )
		timebox.set_field( 1, getValue( timeptr + 4, 'i32' ) >>> 0 )
		timebox.set_field( 2, getValue( timeptr + 8, 'i32' ) )
		return timebox
	},

	glem_time_box_to_struct: function( timebox, timeptr )
	{
		for ( var i = 0; i < 3; i++ )
		{
			setValue( timeptr + ( 4 * i ), timebox.get_field( i ), 'i32' )
		}
	},

	// GlkApi's unicode functions are not TypedArray safe, so we must convert to normal arrays
	// See https://github.com/erkyrath/glkote/issues/27
	glem_buffer_helper: function( func, bufaddr, len, numchars, lowerrest )
	{
		var buf = Array.prototype.slice.call( new Uint32Array( HEAPU8.buffer, bufaddr, len ) )
		var newlen = Glk[ func ]( buf, numchars, lowerrest )
		HEAPU8.set( new Uint8Array( Uint32Array.from( buf ).slice( 0, len ).buffer ), bufaddr )
		return newlen
	},

	glk_buffer_canon_decompose_uni__deps: [ 'glem_buffer_helper' ],
	glk_buffer_canon_decompose_uni: function( bufaddr, len, numchars )
	{
		return _glem_buffer_helper( 'glk_buffer_canon_decompose_uni', bufaddr, len, numchars )
	},

	glk_buffer_canon_normalize_uni__deps: [ 'glem_buffer_helper' ],
	glk_buffer_canon_normalize_uni: function( bufaddr, len, numchars )
	{
		return _glem_buffer_helper( 'glk_buffer_canon_normalize_uni', bufaddr, len, numchars )
	},

	glk_buffer_to_lower_case_uni__deps: [ 'glem_buffer_helper' ],
	glk_buffer_to_lower_case_uni: function( bufaddr, len, numchars )
	{
		return _glem_buffer_helper( 'glk_buffer_to_lower_case_uni', bufaddr, len, numchars )
	},

	glk_buffer_to_upper_case_uni__deps: [ 'glem_buffer_helper' ],
	glk_buffer_to_upper_case_uni: function( bufaddr, len, numchars )
	{
		return _glem_buffer_helper( 'glk_buffer_to_upper_case_uni', bufaddr, len, numchars )
	},

	glk_buffer_to_title_case_uni__deps: [ 'glem_buffer_helper' ],
	glk_buffer_to_title_case_uni: function( bufaddr, len, numchars, lowerrest )
	{
		return _glem_buffer_helper( 'glk_buffer_to_title_case_uni', bufaddr, len, numchars, lowerrest )
	},

	glk_cancel_char_event: function( window )
	{
{'fraction_non_alphanumeric': 0.12662780602753318, 'fraction_numerical': 0.015626937864318492, 'mean_word_length': 4.260273972602739, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348110', 'n_tokens_mistral': 3374, 'n_tokens_neox': 3141, 'n_words': 727}