PHP class to Xojo

So I have this PHP Class that basically spins text. What some people call spintax… But I want to use it in a Desktop application. Pretty new to Xojo, but have been doing PHP for years. Wondering is any people that are PHP and Xojo pros, have an idea of an efficient way to convert this for Desktop. While still be cross platform and not relying on anything Windows or MAC specific.

[code]class Spintax
{
public function process($text)
{
return preg_replace_callback(
‘/\{(((?>[^\{\}]+)|(?R))*)\}/x’,
array($this, ‘replace’),
$text
);
}

public function replace($text)
{
    $text = $this->process($text[1]);
    $parts = explode('|', $text);
    return $parts[array_rand($parts)];
}

}[/code]

So basically what this does is you can feed it something like:

{quick|fast|large} Brown Fox Jumped Over The {Lazy|Sleepy|Passed Out {stupid|dumb|goofy}} Fox.

Then you might get a result like:

[quote]
large Brown Fox Jumped Over The Passed Out stupid Fox.

large Brown Fox Jumped Over The Lazy Fox.

fast Brown Fox Jumped Over The Lazy Fox.

fast Brown Fox Jumped Over The Passed Out goofy Fox.[/quote]

Basically it has a normal Spintax like: {quick|fast|large}

But it also has nested Spintax like: {Lazy|Sleepy|Passed Out {stupid|dumb|goofy}} Fox.

I know this is a rather odd thing, that most people probably wouldn’t have messed with before, but I figured I would ask. :wink:

You can’t convert it directly into xojo, since xojo doesn’t support RegEx replace with callback, but you can use RegEx and co to do the same algorithm.

@Asis Patisahusiwa

Yeah after thinking about it, don’t think it will take much for me to convert it… other then a heck of a lot more lines lol.

Thanks!

Recursive programming is a wonderful thing, so long as it is managed correctly. I suspect @Kem Tekinay could make this work in just as many lines of code.

Shouldn’t this rather be:
Programming is a wonderful thing, so long as it is managed correctly.

Recursive programming has it that it can be more evil than regular programming. So it demands even more careful management :wink:

That said, regular programming run amok can do pretty stupid things too.

I wouldn’t doubt it with some of the things he has done that I have seen from a short time here.