Skip to content

Commit 5befa88

Browse files
authored
Merge pull request #917 from Baltasarq/tostring_isletter_isdigit
Adds isdigit() and isletter() to string.bas
2 parents 4f389e9 + 467dd96 commit 5befa88

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/lib/arch/zx48k/stdlib/string.bas

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,41 @@ function trim(ByVal s$ as String, ByVal rep$ as String) as String
305305
return ltrim(rtrim(s$, rep$), rep$)
306306
end function
307307

308+
309+
' ----------------------------------------------------------------
310+
' function isdigit(ByVal s$)
311+
'
312+
' Returns not 0 if the first element of s$ is a digit,
313+
' or 0 otherwise.
314+
' For example:
315+
' isdigit("a") returns 0, isdigit("2") returns 1
316+
' ----------------------------------------------------------------
317+
function isdigit(ByVal s$ as String) as ubyte
318+
dim asc_key as ubyte = code( s$( 0 ) )
319+
320+
return asc_key >= code( "0" ) _
321+
and asc_key <= code( "9" )
322+
end function
323+
324+
325+
' ----------------------------------------------------------------
326+
' function isletter(ByVal s$)
327+
'
328+
' Returns not 0 if the first element of s$ is a letter,
329+
' or 0 otherwise.
330+
' For example:
331+
' isletter("0") returns 0, isletter("a") returns 1
332+
' ----------------------------------------------------------------
333+
function isletter(ByVal s$ as String) as ubyte
334+
dim asc_key as ubyte = code( s$( 0 ) )
335+
336+
return ( asc_key >= code( "a" ) _
337+
and asc_key <= code( "z" ) ) _
338+
or ( asc_key >= code( "A" ) _
339+
and asc_key <= code( "Z" ) )
340+
end function
341+
342+
308343
#undef __MAX_LEN__
309344

310345
#pragma pop(string_base)

src/lib/arch/zxnext/stdlib/string.bas

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,41 @@ function trim(ByVal s$ as String, ByVal rep$ as String) as String
305305
return ltrim(rtrim(s$, rep$), rep$)
306306
end function
307307

308+
309+
' ----------------------------------------------------------------
310+
' function isdigit(ByVal s$)
311+
'
312+
' Returns not 0 if the first element of s$ is a digit,
313+
' or 0 otherwise.
314+
' For example:
315+
' isdigit("a") returns 0, isdigit("2") returns 1
316+
' ----------------------------------------------------------------
317+
function isdigit(ByVal s$ as String) as ubyte
318+
dim asc_key as ubyte = code( s$( 0 ) )
319+
320+
return asc_key >= code( "0" ) _
321+
and asc_key <= code( "9" )
322+
end function
323+
324+
325+
' ----------------------------------------------------------------
326+
' function isletter(ByVal s$)
327+
'
328+
' Returns not 0 if the first element of s$ is a letter,
329+
' or 0 otherwise.
330+
' For example:
331+
' isletter("0") returns 0, isletter("a") returns 1
332+
' ----------------------------------------------------------------
333+
function isletter(ByVal s$ as String) as ubyte
334+
dim asc_key as ubyte = code( s$( 0 ) )
335+
336+
return ( asc_key >= code( "a" ) _
337+
and asc_key <= code( "z" ) ) _
338+
or ( asc_key >= code( "A" ) _
339+
and asc_key <= code( "Z" ) )
340+
end function
341+
342+
308343
#undef __MAX_LEN__
309344

310345
#pragma pop(string_base)

0 commit comments

Comments
 (0)