Author Topic: StrStartsWith ?  (Read 410 times)

HSE

  • Member
  • *****
  • Posts: 1349
  • <AMD>< 7-32>
StrStartsWith ?
« 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.

Code: [Select]
invoke StrStartsWithA, element, $OfsCStr("TBL")

Regards. HSE

jj2007

  • Member
  • *****
  • Posts: 10461
  • Assembler is fun ;-)
    • MasmBasic
Re: StrStartsWith ?
« Reply #1 on: April 28, 2020, 11:01:35 AM »
What's the difference to .if instr("The string to be tested", "The")==1 ?

HSE

  • Member
  • *****
  • Posts: 1349
  • <AMD>< 7-32>
Re: StrStartsWith ?
« Reply #2 on: April 28, 2020, 11:25:05 AM »
Hi JJ!

The name is more easy :biggrin:
 

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: StrStartsWith ?
« Reply #3 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

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: StrStartsWith ?
« Reply #4 on: April 28, 2020, 05:20:49 PM »

mabdelouahab

  • Member
  • ***
  • Posts: 450
Re: StrStartsWith ?
« Reply #5 on: April 28, 2020, 09:28:02 PM »
glib:    g_str_has_prefix
And :   g_str_has_suffix

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: StrStartsWith ?
« Reply #6 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
« Last Edit: May 02, 2020, 01:43:40 AM by Biterider »

HSE

  • Member
  • *****
  • Posts: 1349
  • <AMD>< 7-32>
Re: StrStartsWith ?
« Reply #7 on: April 28, 2020, 11:48:46 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.

mabdelouahab

  • Member
  • ***
  • Posts: 450
Re: StrStartsWith ?
« Reply #8 on: April 29, 2020, 01:35:15 AM »
Code: [Select]
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;
}

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: StrStartsWith ?
« Reply #9 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