-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#134 new sprintf function allowing multiple key/value replacement #138
Open
Nunalves
wants to merge
2
commits into
OraOpenSource:master
Choose a base branch
from
Nunalves:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,7 +331,106 @@ as | |
return l_return; | ||
|
||
end sprintf; | ||
|
||
|
||
|
||
/** | ||
* Does string replacement of keys by values | ||
* | ||
* @example | ||
* SELECT oos_util_string.sprintf('Hello {firstName} {lastName}!', | ||
* t_tab_key_value(t_rec_key_value('firstName', 'Nuno'), | ||
* t_rec_key_value('lastName', 'Alves') | ||
* ) | ||
* ) demo | ||
* FROM dual; | ||
* | ||
* DEMO | ||
* ------------------------------ | ||
* Hello Nuno Alves! | ||
* | ||
* @issue #134 | ||
* | ||
* @author Nuno Alves | ||
* @created 12-Nov-2016 | ||
* @param p_str Messsage to format using %s and %d replacement strings | ||
* @param p_key_values Nested table of key value pairs to be replaced | ||
* @param p_left_pattern Left string pattern, '{' by default | ||
* @param p_right_pattern Right string pattern, '}' by default | ||
* @return p_msg with strings replaced | ||
*/ | ||
function sprintf( | ||
p_str in varchar2, | ||
p_key_values in t_tab_key_value, | ||
p_left_pattern in varchar2 default '{', | ||
p_right_pattern in varchar2 default '}') | ||
return varchar2 | ||
as | ||
l_return varchar2(4000); | ||
begin | ||
l_return := p_str; | ||
if p_key_values IS NOT NULL AND p_key_values.exists(1) | ||
then | ||
for i in 1 .. p_key_values.count | ||
loop | ||
l_return := REPLACE(l_return, p_left_pattern || p_key_values(i).key || p_right_pattern, p_key_values(i).value); | ||
end loop; | ||
end if; | ||
|
||
return l_return; | ||
end sprintf; | ||
|
||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since all the code is in one PR I'll accept this but remove this function. It's already handled in standard sprintf |
||
* Does string replacement by string position | ||
* | ||
* @example | ||
* select oos_util_string.sprintf('hello {1} {2}!', t_tab_vc2('Nuno','Alves')) demo | ||
* from dual; | ||
* | ||
* DEMO | ||
* ------------------------------ | ||
* Hello Nuno Alves! | ||
* | ||
* select oos_util_string.sprintf('hello {2} {1}!', t_tab_vc2('Nuno','Alves')) demo | ||
* from dual; | ||
* | ||
* DEMO | ||
* ------------------------------ | ||
* Hello Alves Nuno! | ||
* @issue #134 | ||
* | ||
* @author Nuno Alves | ||
* @created 12-Nov-2016 | ||
* @param p_str Messsage to format using %s and %d replacement strings | ||
* @param p_tab_vc2 Nested table of replacement strings | ||
* @param p_left_pattern Left string pattern, '{' by default | ||
* @param p_right_pattern Right string pattern, '}' by default | ||
* @return p_msg with strings replaced | ||
*/ | ||
function sprintf( | ||
p_str in varchar2, | ||
p_tab_vc2 in t_tab_vc2, | ||
p_left_pattern in varchar2 default '{', | ||
p_right_pattern in varchar2 default '}') | ||
return varchar2 | ||
as | ||
l_tab_key_value t_tab_key_value := t_tab_key_value(); | ||
l_return varchar2(4000); | ||
begin | ||
l_return := p_str; | ||
if p_tab_vc2 IS NOT NULL AND p_tab_vc2.exists(1) | ||
then | ||
for i in 1 .. p_tab_vc2.count | ||
loop | ||
l_tab_key_value.extend(1); | ||
l_tab_key_value(i) := t_rec_key_value(i, p_tab_vc2(i)); | ||
end loop; | ||
end if; | ||
|
||
l_return := sprintf(l_return, l_tab_key_value, p_left_pattern, p_right_pattern); | ||
|
||
return l_return; | ||
end sprintf; | ||
|
||
/** | ||
* Converts delimited string to array | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-------------------------------------------------------- | ||
-- DDL for Type T_REC_KEY_VALUE | ||
-------------------------------------------------------- | ||
|
||
CREATE OR REPLACE TYPE "T_REC_KEY_VALUE" | ||
AS | ||
OBJECT | ||
( | ||
KEY VARCHAR2(4000), | ||
VALUE VARCHAR2(4000) | ||
); | ||
|
||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-------------------------------------------------------- | ||
-- DDL for Type T_TAB_KEY_VALUE | ||
-------------------------------------------------------- | ||
|
||
CREATE OR REPLACE TYPE "T_TAB_KEY_VALUE" AS TABLE OF T_REC_KEY_VALUE; | ||
|
||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-------------------------------------------------------- | ||
-- DDL for Type T_TAB_VC2 | ||
-------------------------------------------------------- | ||
|
||
CREATE OR REPLACE TYPE "T_TAB_VC2" as table of varchar2(4000); | ||
|
||
/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll accept this function