String Manipulation in G'MIC

Okay, I will say that I understand that G’MIC is definitely not suitable for string manipulation. However, I found out that you can create a library of command specifically for string manipulation. This thread is to share commands for insertion into the str_manipulation_library. I do think it would be little easier than python at a theoretical level once the library is made.

Here’s a small short library.

rep_str_maniputation_library:

m "create_new_string : ('\"$""1\"') "

m "sarcasm_text : 
 f \"
  is_upper_case=inrange(i,97,122,1,1);
  is_lower_case=inrange(i,65,90,1,1);
  u(0,1)<.5?(
   is_upper_case?i-32:(is_lower_case?i+32:i);
  ):(i);\""

m "call_out_string : u {t} echo ${}"

After you call out the rep_str_manipulation_library, you can access sarcasm_text outside of the command scope.

C:\Windows\System32>gmic rep_str_maniputation_library create_new_string "This is super!" sarcasm_text. call_out_string. rm.
[gmic]-0./ Start G'MIC interpreter.
[gmic]-1./call_out_string/ this IS SuPeR!
[gmic]-1./ Remove image [0] (0 images left).
[gmic]-0./ End G'MIC interpreter.

Good stuff. Does it do spelling corrections?

1 Like

No, and there’s no way to do that. It’s just a set of commands embedded within a command for usage of manipulating images with unicode values.

I should do a smiley face or something.

I considered this myself, but bear in mind one major problem - there’s no native handling of encoding. Without looking at the source, strings are probably UTF-8. That’s a variable width encoding. If you stick to single byte encoded chars you can do a certain amount, but outside that it would be a lot of work…

1 Like