/* Copyright (c) 2000 by Kevin Forchione. All Rights Reserved. */
/*
* TADS ADV.T/STD.T LIBRARY EXTENSION
* REPLACEWITH.T
* version 1.0
*
* ReplaceWith provides an easy way to replace string search values
* with target values using regular expression searches.
*
*----------------------------------------------------------------------
* REQUIREMENTS
*
* + HTML TADS 2.3.0 or later
*
*----------------------------------------------------------------------
* IMPORTANT LIBRARY INTERFACE AND MODIFICATION
*
* None.
*
*----------------------------------------------------------------------
* COPYRIGHT NOTICE
*
* You may modify and use this file in any way you want, provided that
* if you redistribute modified copies of this file in source form, the
* copies must include the original copyright notice (including this
* paragraph), and must be clearly marked as modified from the original
* version.
*
*------------------------------------------------------------------------------
* REVISION HISTORY
*
* 09-Feb-2000: Creation.
*/
/*
* replaceWith(value, target, replacement, flags)
*
* The function searches the value string, replacing the target string
* with the replacement string.
*
* Bit-flags can be passed to control the search.
*
* RW_REPLACE_ONCE replace only one occurrence of the target in the
* value string.
*
* The default for replaceWith() is to replace all occurrences
* of the target in the value string.
*
* RW_MATCH_WORD target must match whole words. For example:
*
* target 'get in' will search for '%<get>% *%<in%>'
* which will match 'get in the chair', but not
* 'get into the chair'
*
* RW_MATCH_CASE target must match the case in value.
*
* The default for replaceWith() is case-insensitive. A target
* string of 'get into' will match on 'GET INTO THE CAR' as
* well as 'Get into the car' unless RW_MATCH_CASE is used.
*
* RW_RET_NIL function returns nil if no match for the target found
*
* The default for replaceWith() returns the value unchanged.
* Using RW_RET_NIL will return the value only if replacement
* occurred; otherwise the function will return nil.
*/
replaceWith: function(value, target, replacement, ...)
{
local ret, new_value = '';
local valuesave, targetsave, replacementsave;
local flags = 0;