From 674fe67e242ab45bcc65799af363ea1611c47f20 Mon Sep 17 00:00:00 2001 From: Morten Braten Date: Wed, 13 May 2015 19:27:40 +0200 Subject: [PATCH 1/3] Created coding standards document --- doc/coding_standards.txt | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 doc/coding_standards.txt diff --git a/doc/coding_standards.txt b/doc/coding_standards.txt new file mode 100644 index 0000000..7fbc6f7 --- /dev/null +++ b/doc/coding_standards.txt @@ -0,0 +1,41 @@ +Coding Standards +for the +Alexandria PL/SQL Utility Library +================================= + +Please follow the following coding conventions if you want to contribute to the library. +The best way to write compliant code is to familiarize yourself with the existing code and try to adapt a similar style. + +General +------- + +* Files should use Windows line endings. Any decent editor will understand both Windows and Unix line endings, but by sticking to Windows line endings the files can be viewed without problems even in "dumb" editors such as Notepad. +* Make sure your Git client is set to "checkout as-is, commit as-is" with respect to line endings. See https://help.github.com/articles/dealing-with-line-endings/ and http://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings for more information. + +Case +---- +* All identifiers, built-in functions, packages and other code should be written in lowercase. +* Use underscores between words. +* CORRECT: get_invoice_totals +* WRONG: GET_INVOICE_TOTALS +* WRONG: getInvoiceTotals + +Indentation +----------- +* Identation size is 2 spaces +* Do not use tabs, always use spaces + +Naming Conventions +------------------ +* All packages should be postfixed with _pkg +* All parameters should be prefixed with p_ +* All local variables should be prefixed with l_ +* All private "module"-level (ie package body-level) variables should be prefixed with m_ +* All public "global" (ie package specification-level) variables should be prefixed with g_ +* All public "global" (ie package specification-level) constants should be prefixed with c_ (note: this is not done consistently in existing code, where constants are commonly prefixed with g_ instead, but new code should use the c_ prefix) + +Other +----- +* All program units (functions and procedures) must have a standard comment block that explains the purpose of the program unit, as well as a change log that includes the author's initials (max 3 characters), date (using format DD.MM.YYYY) and a description of the change +* All functions must define a local variable called "l_returnvalue" and the last statement in any function should be "return l_returnvalue;". Do not write functions with multiple return statements, and do not write procedures with any return statements. +* Always include (repeat) the name of the program unit in the final "end" statement at the end of the program unit. From d3af944d273b5a03fee92e04de2618807d8077eb Mon Sep 17 00:00:00 2001 From: Matthew Hasbach Date: Tue, 12 May 2015 17:50:06 -0400 Subject: [PATCH 2/3] string_util_pkg.str_to_bool_str now leverages string_util_pkg.str_to_bool in order to reduce code redundancy --- ora/string_util_pkg.pkb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ora/string_util_pkg.pkb b/ora/string_util_pkg.pkb index de009e6..028e4d8 100755 --- a/ora/string_util_pkg.pkb +++ b/ora/string_util_pkg.pkb @@ -694,10 +694,11 @@ begin Who Date Description ------ ---------- ------------------------------------- MBR 06.01.2009 Created + MJH 12.05.2015 Leverage string_util_pkg.str_to_bool in order to reduce code redundancy */ - if lower(p_str) in ('y', 'yes', 'true', '1') then + if str_to_bool(p_str) then l_returnvalue := g_yes; end if; From 01f129e2a58d051e3b1389ac7c0ce3a08345f240 Mon Sep 17 00:00:00 2001 From: Matthew Hasbach Date: Tue, 12 May 2015 17:37:29 -0400 Subject: [PATCH 3/3] Added string_util_pkg.is_str_alphanumeric --- ora/string_util_pkg.pkb | 22 ++++++++++++++++++++++ ora/string_util_pkg.pks | 3 +++ 2 files changed, 25 insertions(+) diff --git a/ora/string_util_pkg.pkb b/ora/string_util_pkg.pkb index de009e6..8c70058 100755 --- a/ora/string_util_pkg.pkb +++ b/ora/string_util_pkg.pkb @@ -487,6 +487,28 @@ begin end remove_non_alpha_chars; +function is_str_alphanumeric (p_str in varchar2) return boolean +as + l_returnvalue boolean; +begin + + /* + + Purpose: returns true if string is alphanumeric + + Who Date Description + ------ ---------- ------------------------------------- + MJH 12.05.2015 Created + + */ + + l_returnvalue := regexp_instr(p_str, '[^a-z|A-Z|0-9]') = 0; + + return l_returnvalue; + +end is_str_alphanumeric; + + function is_str_empty (p_str in varchar2) return boolean as l_returnvalue boolean; diff --git a/ora/string_util_pkg.pks b/ora/string_util_pkg.pks index 3fbc4db..a665e5d 100755 --- a/ora/string_util_pkg.pks +++ b/ora/string_util_pkg.pks @@ -92,6 +92,9 @@ as -- remove all non-alpha characters (A-Z) from string function remove_non_alpha_chars (p_str in varchar2) return varchar2; + -- returns true if string is alphanumeric + function is_str_alphanumeric (p_str in varchar2) return boolean; + -- returns true if string is "empty" (contains only whitespace characters) function is_str_empty (p_str in varchar2) return boolean;