The MASM Forum

Projects => ObjAsm => Topic started by: HSE on April 28, 2020, 10:18:13 AM

Title: StrStartsWith ?
Post by: HSE on April 28, 2020, 10:18:13 AM
Hi Biterider!

I found interesting to make a little modification of StrLCompA to mimic a function available in Java. In theory is going to work. 

Perhaps you could add something similar to ObjAsm package.

invoke StrStartsWithA, element, $OfsCStr("TBL")


Regards. HSE
Title: Re: StrStartsWith ?
Post by: jj2007 on April 28, 2020, 11:01:35 AM
What's the difference to .if instr("The string to be tested", "The")==1 ?
Title: Re: StrStartsWith ?
Post by: HSE on April 28, 2020, 11:25:05 AM
Hi JJ!

The name is more easy :biggrin:
Title: Re: StrStartsWith ?
Post by: Biterider on April 28, 2020, 04:52:45 PM
Hi HSE
Good idea  :icon_idea:
What is the expected return value of the Java function, TRUE/FALSE?



Biterider
Title: Re: StrStartsWith ?
Post by: Biterider on April 28, 2020, 05:20:49 PM
OK, found it https://beginnersbook.com/2013/12/java-string-startswith-method-example/ (https://beginnersbook.com/2013/12/java-string-startswith-method-example/)

I'll add it.

Biterider
Title: Re: StrStartsWith ?
Post by: mabdelouahab on April 28, 2020, 09:28:02 PM
glib:    g_str_has_prefix (https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-str-has-prefix)
And :   g_str_has_suffix (https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-str-has-suffix)
Title: Re: StrStartsWith ?
Post by: Biterider on April 28, 2020, 09:39:17 PM
Hi HSE
Here is a quick update of the ObjMem library. It contains all changed files since the C.1.0 release and StrStartsWith (ANSI, WIDE & BSTR) for 32/64 bit.

@mabdelouahab: "g_str_has_suffix" is a good idea => StrEndsWith. Maybe I'll implement it too.

Biterider
Title: Re: StrStartsWith ?
Post by: HSE on April 28, 2020, 11:48:46 PM
Quote from: Biterider on April 28, 2020, 09:39:17 PM
Here is a quick update of the ObjMem library. It contains all changed files since the C.1.0 release and StrStartsWith (ANSI, WIDE & BSTR) for 32/64 bit.
Fantastic  :thumbsup:

But you are the author.  I just give the idea (fortunately, in ASCII, you can't write that in small letters  :biggrin:)

Thanks.
Title: Re: StrStartsWith ?
Post by: mabdelouahab on April 29, 2020, 01:35:15 AM

int strncmp(const char *s1, const char *s2, size_t n) {
while (1) {
if (n <= 0)
return 0;
if (*s1 != *s2)
return *s1 - *s2;
if (*s1 == 0)
return 0;
s1++;
s2++;
n--;
}
}
gboolean g_str_has_suffix(const gchar *str, const gchar *suffix) {
size_t str_length;
size_t suffix_length;

g_return_val_if_fail(str != NULL, FALSE);
g_return_val_if_fail(suffix != NULL, FALSE);

str_length = strlen(str);
suffix_length = strlen(suffix);

return suffix_length <= str_length ?
strncmp(str + str_length - suffix_length, suffix, suffix_length) == 0 :
FALSE;
}
gboolean g_str_has_prefix(const gchar *str, const gchar *prefix) {
size_t str_length;
size_t prefix_length;

g_return_val_if_fail(str != NULL, FALSE);
g_return_val_if_fail(prefix != NULL, FALSE);

str_length = strlen(str);
prefix_length = strlen(prefix);

return prefix_length <= str_length ?
strncmp(str, prefix, prefix_length) == 0 :
FALSE;
}
Title: Re: StrStartsWith ?
Post by: Biterider on April 30, 2020, 12:55:08 AM
Hi
For the record, I added StrEndsWith to the ObjMem library too.
It will be available soon in the next update unless someone needs it earlier.

Biterider