// SPDX-License-Identifier: Apache-2.0
/*
 * Copyright 2001-2026 Richard Lesh
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define	iFMT_DEC			301
#define	iFMT_HEX			302
#define	iFMT_FLOAT			303
#define	iPARSE_INT			304
#define	iPARSE_DEC			305
#define	iPARSE_HEX			306
#define	iPARSE_FLOAT		307
#define	iSPRINTF			308
#define iFORMAT				309

#define	iTO_LOWER			310
#define	iTO_UPPER			311
#define	iTO_LOWER_STR		312
#define	iTO_UPPER_STR		313
#define iSTRCOPY			314
#define iSTRCMP				315
#define	iSTRICMP			316
#define iSUBSTRING			317
#define	iPREFIX				318
#define iSUFFIX				319
#define iCHAR_SEARCH		320
#define iLAST_CHAR_SEARCH	321
#define iSUBSTRING_SEARCH	322
#define iLAST_SUBSTRING_SEARCH	323
#define iGET_CODEPOINTS		324
#define iFROM_CODEPOINTS	325
#define iCOUNT_GLPYHS		326
#define iHASHCODE			327
#define iTRIM				328

#define	iMATCHES			350
#define	iREPLACE_FIRST		351
#define iREPLACE_ALL		352
#define	iSPLIT				353
#define	iJOIN				354
#define	iSTRCAT				355

#def_macro	FMT_DEC(x)
	move	r1, ${x}
	int		iFMT_DEC
#end_macro

#def_macro	FMT_HEX(x)
	move	r1, ${x}
	int		iFMT_HEX
#end_macro

#def_macro	FMT_FLOAT(x)
	move	f1, ${x}
	int		iFMT_FLOAT
#end_macro

#def_macro	PARSE_INT(x)
	move	r1, ${x}
	int		iPARSE_INT
#end_macro

#def_macro	PARSE_DEC(x)
	move	r1, ${x}
	int		iPARSE_DEC
#end_macro

#def_macro	PARSE_HEX(x)
	move	r1, ${x}
	int		iPARSE_HEX
#end_macro

#def_macro	PARSE_FLOAT(x)
	move	r1, ${x}
	int		iPARSE_FLOAT
#end_macro

#def_macro	TO_LOWER(x)
	move	r1, ${x}
	int		iTO_LOWER
#end_macro

#def_macro	TO_UPPER(x)
	move	r1, ${x}
	int		iTO_UPPER
#end_macro

#def_macro	TO_LOWER_STR(x)
	move	r1, ${x}
	int		iTO_LOWER_STR
#end_macro

#def_macro	TO_UPPER_STR(x)
	move	r1, ${x}
	int		iTO_UPPER_STR
#end_macro

#def_macro	STRLEN(s1)
	load	r0, ${s1}[0]
#end_macro

#def_macro	STRCOPY(s1)
	move	r1, ${s1}
	int		iSTRCOPY
#end_macro

#def_macro	STRCMP(s1, s2)
	move	r1, ${s1}
	move	r2, ${s2}
	int		iSTRCMP
#end_macro

#def_macro	SUBSTRING(s, start, length)
	move	r1, ${s}
	move	r2, ${start}
	move	r3, ${length}
	int		iSUBSTRING
#end_macro

#def_macro	PREFIX(s, length)
	move	r1, ${s}
	move	r2, ${length}
	int		iPREFIX
#end_macro

#def_macro	SUFFIX(s, length)
	move	r1, ${s}
	move	r2, ${length}
	int		iSUFFIX
#end_macro

#def_macro	CHAR_SEARCH(s, char, startpos)
	move	r1, ${s}
	move	r2, ${char}
	move	r3, ${startpos}
	int		iCHAR_SEARCH
#end_macro

#def_macro	LAST_CHAR_SEARCH(s, char, startpos)
	move	r1, ${s}
	move	r2, ${char}
	move	r3, ${startpos}
	int		iLAST_CHAR_SEARCH
#end_macro

#def_macro	SUBSTRING_SEARCH(s, substr, startpos)
	move	r1, ${s}
	move	r2, ${substr}
	move	r3, ${startpos}
	int		iSUBSTRING_SEARCH
#end_macro

#def_macro	LAST_SUBSTRING_SEARCH(s, substr, startpos)
	move	r1, ${s}
	move	r2, ${substr}
	move	r3, ${startpos}
	int		iLAST_SUBSTRING_SEARCH
#end_macro

///////////////////////////////////////////////////////////////////////////////
// STARTS_WITH(str, prefix) - Checks to see if the string begins with prefix
// str		Base address of string to search
// prefix	Prefix to cehck for
// Returns 	TRUE if prefix matches, otherwise FALSE
///////////////////////////////////////////////////////////////////////////////
#def_macro	STARTS_WITH(str, prefix)
	#macro	SUBSTRING_SEARCH(${str}, ${prefix}, 0)
	move	z, r0, TRUE, FALSE
#end_macro

///////////////////////////////////////////////////////////////////////////////
// ENDS_WITH(str, suffix) - Checks to see if the string ends with suffix
// str		Base address of string to search
// suffix	Suffix to cehck for
// Returns 	TRUE if suffix matches, otherwise FALSE
///////////////////////////////////////////////////////////////////////////////
#def_macro	ENDS_WITH(str, suffix)
	load	r1, ${str}[0]
	load	r2, ${suffix}[0]
	sub		r3, r1, r2
	move	r1, ${str}
	move	r2, ${suffix}
	int		iLAST_SUBSTRING_SEARCH
	cmp		r0, r3
	move	z, r0, TRUE, FALSE
#end_macro

#def_macro	STRICMP(s1, s2)
	move	r1, ${s1}
	move	r2, ${s2}
	int		iSTRICMP
#end_macro

#def_macro	GET_CODEPOINTS(str)
	move	r1, ${str}
	int		iGET_CODEPOINTS
#end_macro

#def_macro	FROM_CODEPOINTS(arr)
	move	r1, ${arr}
	int		iFROM_CODEPOINTS
#end_macro

#def_macro	COUNT_GLPYHS(str)
	move	r1, ${str}
	int		iCOUNT_GLPYHS
#end_macro

#def_macro	HASH_CODE(str)
	move	r1, ${str}
	int		iHASHCODE
#end_macro

#def_macro	TRIM(str)
	move	r1, ${str}
	int		iTRIM
#end_macro

#def_macro	MATCHES(str, pattern)
	move	r1, ${str}
	move	r2, ${pattern}
	int		iMATCHES
#end_macro

#def_macro	REPLACE_FIRST(str, pattern, replacement)
	move	r1, ${str}
	move	r2, ${pattern}
	move	r3, ${replacement}
	int		iREPLACE_FIRST
#end_macro

#def_macro	REPLACE_ALL(str, pattern, replacement)
	move	r1, ${str}
	move	r2, ${pattern}
	move	r3, ${replacement}
	int		iREPLACE_ALL
#end_macro

#def_macro	SPLIT(str, delimiter)
	move	r1, ${str}
	move	r2, ${delimiter}
	int		iSPLIT
#end_macro

#def_macro	JOIN(arr, delimiter)
	move	r1, ${arr}
	move	r2, ${delimiter}
	int		iJOIN
#end_macro

#def_macro	STRCAT(s1, s2)
	move	r1, ${s1}
	move	r2, ${s2}
	int		iSTRCAT
#end_macro
