JString
JPrepArgForExec
	(
	const JCharacter* arg
	)
{
	JString str    = arg;
	JBoolean quote = kJFalse;

	const JSize length = str.GetLength();
	for (JIndex i=length; i>=1; i--)
		{
		const JCharacter c = str.GetCharacter(i);
		if (c == '"' || c == '\'' || c == '\\' || c == ';')
			{
			str.InsertSubstring("\\", i);
			}
		else if (isspace(c))
			{
			quote = kJTrue;
			}
		}

	if (quote)
		{
		str.PrependCharacter('"');
		str.AppendCharacter('"');
		}
	return str;
}
void
JDirInfo::AppendRegex
	(
	const JCharacter*	origStr,
	JString*			regexStr
	)
{
JIndex i;

	JString str = origStr;

	// Convert wildcard multiples (*) to regex multiples (.*)
	// and wildcard singles (?) to regex singles (.)

	for (i = str.GetLength(); i>=1; i--)
		{
		const JCharacter c = str.GetCharacter(i);
		if (c == '*')
			{
			str.InsertSubstring(".", i);
			}
		else if (c == '?')
			{
			str.SetCharacter(i, '.');
			}
		else if (JRegex::NeedsBackslashToBeLiteral(c))
			{
			str.InsertSubstring("\\", i);
			}
		}

	// Add instructions that it must match the entire file name.

	str.PrependCharacter('^');
	str.AppendCharacter('$');

	// append to regexStr

	if (!regexStr->IsEmpty())
		{
		regexStr->AppendCharacter('|');
		}
	*regexStr += str;
}