From 5e39540e6fa6124954fd14b3d37a2f1ff4aa9caf Mon Sep 17 00:00:00 2001 From: Guillaume Devailly Date: Tue, 12 Dec 2017 13:36:45 +0100 Subject: [PATCH 1/3] Update str_sentence_case.R Add simple implementation of str_sentence_case --- R/str_sentence_case.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/str_sentence_case.R b/R/str_sentence_case.R index 6e5fed1..281cd2c 100644 --- a/R/str_sentence_case.R +++ b/R/str_sentence_case.R @@ -8,5 +8,8 @@ #' #' @export -str_sentence_case <- function( string ) - stop( "Sentence case is not implemented yet.") \ No newline at end of file +str_sentence_case <- function( string ) { + # stolent from https://stackoverflow.com/questions/18509527/first-letter-to-upper-case + substr(string, 1, 1) <- toupper(substr(string, 1, 1)) + string +} From 1d691f59de7fd1f4c663160e5c43b1b61d88cc63 Mon Sep 17 00:00:00 2001 From: Guillaume Devailly Date: Tue, 12 Dec 2017 13:53:18 +0100 Subject: [PATCH 2/3] Update str_sentence_case.R improve implementation should now work as expected --- R/str_sentence_case.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/str_sentence_case.R b/R/str_sentence_case.R index 281cd2c..04f2781 100644 --- a/R/str_sentence_case.R +++ b/R/str_sentence_case.R @@ -9,7 +9,9 @@ #' @export str_sentence_case <- function( string ) { - # stolent from https://stackoverflow.com/questions/18509527/first-letter-to-upper-case - substr(string, 1, 1) <- toupper(substr(string, 1, 1)) - string + # adapted from https://stackoverflow.com/questions/18509527/first-letter-to-upper-case + # behave as expected, even for short string (i.e. "" or "a") + substr(string, 1, 1) <- toupper(substr(string, 1, 1)) + substr(string, 2, nchar(string)) <- tolower(substr(string, 1, nchar(string))) + string } From f77a44b74a900465445fbfa1da0aae310b22a687 Mon Sep 17 00:00:00 2001 From: Guillaume Devailly Date: Tue, 12 Dec 2017 13:54:30 +0100 Subject: [PATCH 3/3] Update str_sentence_case.R removing bug --- R/str_sentence_case.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/str_sentence_case.R b/R/str_sentence_case.R index 04f2781..16d344a 100644 --- a/R/str_sentence_case.R +++ b/R/str_sentence_case.R @@ -12,6 +12,6 @@ str_sentence_case <- function( string ) { # adapted from https://stackoverflow.com/questions/18509527/first-letter-to-upper-case # behave as expected, even for short string (i.e. "" or "a") substr(string, 1, 1) <- toupper(substr(string, 1, 1)) - substr(string, 2, nchar(string)) <- tolower(substr(string, 1, nchar(string))) + substr(string, 2, nchar(string)) <- tolower(substr(string, 2, nchar(string))) string }