|
 |
Josh English <Jos### [at] joshuarenglish com> wrote:
> I'm trying another "push POV-Ray to a new level" and I'm messing around
> with strings.
>
> Unfortunately the SDL doesn't even have a FIND function or STRIP
> function for strings.
As clipka has mentioned in the past, there's really very little in terms of
string manipulation in povray.
> I'm trying to roll my own and getting a bit frustrated.
Well, as always, post your goal and the code, and we'll see what we can do.
> Has anyone implemented string functions in the SDL?
I'm certain I must have in the past. Whether I can find it or not...
> I'm not finding much
> in regular web searches these days.
Yep. Those search engines don't return much of use anymore.
- BE
Post a reply to this message
|
 |
|
 |
On 10/4/2026 4:55 PM, Bald Eagle wrote:
> Josh English <Jos### [at] joshuarenglish com> wrote:
>
>> I'm trying to roll my own and getting a bit frustrated.
>
> Well, as always, post your goal and the code, and we'll see what we can do.
>
>> Has anyone implemented string functions in the SDL?
>
> I'm certain I must have in the past. Whether I can find it or not...
>
I was hoping there was a quick "oh yeah and here's the link" to review.
I think I have a working strip(), split(), and join() functions, and I
think I got there through luck more than actually thinking through the
problem:
// ---------------------------------------------------------------------
// strip(string)
// Extract the first non-space word of a text, up to the following space
#macro strip(string)
#local res = "";
#local I = 1;
#while(substr(string,I,1) = " ") #local I = I + 1; #end
#local next_c = 0;
#while (substr(string,I,1) != " ")
#local res = concat(res, substr(string, I, 1));
#local next_c = next_c + 1;
#local I = I + 1;
#if(I > strlen(string)) #break #end
#end
res
#end
// split(string)
// split a string by spaces
#macro split(string)
#local len = strlen(string);
#local I = 1;
#declare res = array;
#while(I <= len)
#local next = strip(substr(string, I, len-I+1));
//#debug concat("-",next, "-\n")
#local I = I + strlen(next)+1;
#declare res[dimension_size(res, 1)] = next;
#end
res
#end // macro split
// join(array)
// joins an array of strings into a single text by spaces
#macro join(arr)
#local res = "";
#for(I,0,dimension_size(arr,1)-1, 1)
#local res = concat(res, arr[I], " ");
#end
substr(res, 1 strlen(res)-1)
#end
// ---------------------------------------------------------------------
It seems to work for my purposes, which are stupidly complicated, as always.
-- Uncle Josh
Post a reply to this message
|
 |
|
 |
hi,
Josh English <Jos### [at] joshuarenglish com> wrote:
> ...
> Has anyone implemented string functions in the SDL? I'm not finding much
> in regular web searches these days.
I wrote a 'strSplit()' to convert a string to an array of strings:
<wiki.povray.org/content/User:Jr/assorted>
regards, jr.
Post a reply to this message
|
 |
|
 |
I built these, in case anyone finds them useful.
#macro h2d(HexVal)
(asc(HexVal)>64?asc(HexVal)-55:asc(HexVal)-48)
#end
#macro hex2rgb(hxStr)
<(16*h2d(substr(hxStr,4,1))+h2d(substr(hxStr,5,1)))/255,(16*h2d(substr(hxStr,6,1))+h2d(substr(hxStr,7,1)))/255,
(16*h2d(substr(hxStr,8,1))+h2d(substr(hxStr,9,1)))/255>
#end
Post a reply to this message
|
 |