Class Pot.Text.ReplaceSaver
Defined in: <pot.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Pot.Text.ReplaceSaver(string, pattern, (reserve))
This class will be replace a particular string to temporary string,
and execute the conventional process,
and after back replace to the original string,
these heavy step so just to make easier by this function.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Pot.Text.ReplaceSaver.load(result)
Load the original string from saved string.
|
<static> |
Pot.Text.ReplaceSaver.save()
Save the string by specified pattern(s).
|
<static> |
Pot.Text.ReplaceSaver.setPattern(pattern)
Set the pattern(s).
|
<static> |
Pot.Text.ReplaceSaver.setReserve(reserve)
Set the reserve keyword(s).
|
<static> |
Pot.Text.ReplaceSaver.setString(string)
Set the string.
|
<static> |
Pot.Text.ReplaceSaver.toString()
toString.
|
Class Detail
Pot.Text.ReplaceSaver(string, pattern, (reserve))
This class will be replace a particular string to temporary string,
and execute the conventional process,
and after back replace to the original string,
these heavy step so just to make easier by this function.
// This sample code is process to leaving only the 'pre' tags, // and replace all other HTML tags are escaped. var myProcess = function(string) { return string.replace(/&/g, '&'). replace(/</g, '<'). replace(/>/g, '>'); }; var string = '<pre>\n' + '<b>var</b> foo = 1;\n' + '</pre>\n' + '<div>hoge</div>\n' + '<div>fuga</div>\n' + '<p onclick="alert(1)">piyo</p>\n' + '<pre>\n' + '<b>foo</b>\n' + 'bar\n' + '<i>baz</i>\n' + '</pre>'; var pattern = /<pre\b[^>]*>([\s\S]*?)<\/pre>/gi; // The string or Array that must not appear in the saved string. var reserve = ['<', '>']; var rs = new Pot.Text.ReplaceSaver(string, pattern, reserve); // Save and replace string for your replace process. var result = rs.save(); // Execute your replace process. result = myProcess(result); // Load and replace from saved string. result = rs.load(result); debug(result); // @results // <pre> // <b>var</b> foo = 1; // </pre> // <div>hoge</div> // <div>fuga</div> // <p onclick="alert(1)">piyo</p> // <pre> // <b>foo</b> // bar // <i>baz</i> // </pre>
- Parameters:
- {String} string
- The target string.
- {String|RegExp|Array} pattern
- The pattern(s) to save string.
- {String|Array} (reserve)
- The reserve keyword(s) for your replace process.
- Returns:
- {Pot.ReplaceSaver} Returns an instance of Pot.ReplaceSaver.
Method Detail
<static>
{Function}
Pot.Text.ReplaceSaver.load(result)
Load the original string from saved string.
- Parameters:
- {String} result
- The saved string.
- Returns:
- {String} Returns the original string.
<static>
{Function}
Pot.Text.ReplaceSaver.save()
Save the string by specified pattern(s).
// This sample code is process to leaving only the 'pre' tags, // and replace all other HTML tags are escaped. var myProcess = function(string) { return string.replace(/&/g, '&'). replace(/</g, '<'). replace(/>/g, '>'); }; var string = '<pre>\n' + '<b>var</b> foo = 1;\n' + '</pre>\n' + '<div>hoge</div>\n' + '<div>fuga</div>\n' + '<p onclick="alert(1)">piyo</p>\n' + '<pre>\n' + '<b>foo</b>\n' + 'bar\n' + '<i>baz</i>\n' + '</pre>'; var pattern = /<pre\b[^>]*>([\s\S]*?)<\/pre>/gi; // The string or Array that must not appear in the saved string. var reserve = ['<', '>']; var rs = new Pot.Text.ReplaceSaver(string, pattern, reserve); // Save and replace string for your replace process. var result = rs.save(); // Execute your replace process. result = myProcess(result); // Load and replace from saved string. result = rs.load(result); debug(result); // @results // <pre> // <b>var</b> foo = 1; // </pre> // <div>hoge</div> // <div>fuga</div> // <p onclick="alert(1)">piyo</p> // <pre> // <b>foo</b> // bar // <i>baz</i> // </pre>
- Returns:
- {String} Returns a string that is replaced by specified pattern(s).
<static>
{Function}
Pot.Text.ReplaceSaver.setPattern(pattern)
Set the pattern(s).
- Parameters:
- {String|RegExp|Array} pattern
- The pattern(s).
- Returns:
- {Pot.ReplaceSaver} Return this.
<static>
{Function}
Pot.Text.ReplaceSaver.setReserve(reserve)
Set the reserve keyword(s).
- Parameters:
- {String|Array} reserve
- The reserve keyword(s).
- Returns:
- {Pot.ReplaceSaver} Return this.
<static>
{Function}
Pot.Text.ReplaceSaver.setString(string)
Set the string.
- Parameters:
- {String} string
- The target string.
- Returns:
- {Pot.ReplaceSaver} Return this.
<static>
{Function}
Pot.Text.ReplaceSaver.toString()
toString.
- Returns:
- Return formatted string of object.