Skip to content

Commit

Permalink
use ICU to define sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Jan 20, 2021
1 parent bc615c5 commit 3c13bfc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# git2rdata 0.3.1

* Use `icuSetCollate()` to define a standardised sorting.

# git2rdata 0.3.0

## New features
Expand Down
16 changes: 6 additions & 10 deletions R/datahash.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,18 @@ datahash <- function(file) {
#' @noRd
#' @return a named vector with the old locale
set_c_locale <- function() {
old_ctype <- Sys.getlocale(category = "LC_CTYPE")
old_collate <- Sys.getlocale(category = "LC_COLLATE")
old_time <- Sys.getlocale(category = "LC_TIME")
Sys.setlocale(category = "LC_CTYPE", locale = "C")
Sys.setlocale(category = "LC_COLLATE", locale = "C")
Sys.setlocale(category = "LC_TIME", locale = "C")
return(c(ctype = old_ctype, collate = old_collate, time = old_time))
icuSetCollate(
locale = "en_GB", case_first = "lower", normalization = "on",
case_level = "on"
)
return(c())
}

#' Reset the old locale
#' @param locale the output of `set_c_locale()`
#' @return invisible `NULL`
#' @noRd
set_local_locale <- function(locale) {
Sys.setlocale(category = "LC_CTYPE", locale = locale["ctype"])
Sys.setlocale(category = "LC_COLLATE", locale = locale["collate"])
Sys.setlocale(category = "LC_TIME", locale = locale["time"])
icuSetCollate(locale = "default")
return(invisible(NULL))
}
4 changes: 2 additions & 2 deletions tests/testthat/test_b_special.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ expect_is(
)
expect_equal(
names(output)[1],
"9e5edf55ceadd2c148d6d715ea5d12cc8e1538d8"
"1d135a85dc9beff3223d6c79f0d8975b559afca7"
)
old_locale <- git2rdata:::set_c_locale()
dso <- ds[order(ds$a), , drop = FALSE] # nolint
Expand Down Expand Up @@ -64,7 +64,7 @@ expect_equal(
)
expect_equal(
names(output)[1],
"9e5edf55ceadd2c148d6d715ea5d12cc8e1538d8"
"1d135a85dc9beff3223d6c79f0d8975b559afca7"
)
expect_identical(
names(output),
Expand Down

0 comments on commit 3c13bfc

Please sign in to comment.