Skip to content

Commit 9ccfb52

Browse files
committed
put all key sorting funs in common format fun env
1 parent 3af074a commit 9ccfb52

File tree

3 files changed

+56
-87
lines changed

3 files changed

+56
-87
lines changed

R/05makeBibLatex.R

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -77,55 +77,6 @@ MakeBibLaTeX <- function(docstyle = "text", authortitle = FALSE) {
7777
addPeriod(res)
7878
}
7979

80-
sortKeysLA <- function(bib, yrs){
81-
result <- character(length(bib))
82-
max.names <- .BibOptions$max.names
83-
for (i in seq_along(bib)) {
84-
res <- bib[[i]]$shorthand
85-
if (!length(res)){
86-
res <- bib[[i]]$label
87-
if (!length(res))
88-
res <- ProcessNamesLA(bib[[i]]$shortauthor, max.names)
89-
if (!length(res))
90-
res <- ProcessNamesLA(bib[[i]]$shorteditor, max.names)
91-
if (!length(res))
92-
res <- ProcessNamesLA(bib[[i]]$author, max.names)
93-
if (!length(res))
94-
res <- ProcessNamesLA(bib[[i]]$editor, max.names)
95-
if (!length(res))
96-
res <- ProcessNamesLA(bib[[i]]$translator, max.names)
97-
res <- paste0(res, substr(yrs[i], 3, 4))
98-
}
99-
result[i] <- res
100-
}
101-
result
102-
}
103-
104-
ProcessNamesLA <- function(nam, mn = .BibOptions$max.names){
105-
nam.len <- length(nam)
106-
if (nam.len){
107-
if (!inherits(nam, 'person'))
108-
nam <- ArrangeAuthors(nam)
109-
if (nam.len == 1){
110-
res <- paste0(nam$family, collapse = '')
111-
res <- regmatches(res, regexpr('[[:upper:]][[:punct:]]?[[:alpha:]][[:punct:]]?[[:alpha:]]',
112-
res, useBytes = TRUE))
113-
res <- gsub('[[:punct:]]', '', res, useBytes = TRUE)
114-
}else if (nam.len == 2 || nam.len == 3){
115-
res <- sapply(nam$family, paste0, collapse = '')
116-
res <- paste0(regmatches(res, regexpr('[[:upper:]]', res, useBytes = TRUE)), collapse = '')
117-
}else{
118-
res <- paste0(nam$family[[1]], collapse = '')
119-
res <- regmatches(res, regexpr('[[:upper:]][[:punct:]]?[[:alpha:]][[:punct:]]?[[:alpha:]]',
120-
res, useBytes = TRUE))
121-
res <- gsub('[[:punct:]]', '', res, useBytes = TRUE)
122-
res <- paste0(res, '+')
123-
}
124-
res
125-
}
126-
}
127-
128-
12980
sortKeysV <- function(bib){
13081
result <- numeric(length(bib))
13182
for (i in seq_along(bib)){

R/07makeBibLatexAuthoryear.R

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,14 @@ MakeAuthorYear <- function(docstyle = "text"){
3434
sub("([^.?!])$", "\\dQuote{\\1.}", string, useBytes = TRUE)
3535
}
3636

37-
GetLastNames <- function(bib){
38-
result <- character(length(bib))
39-
for (i in seq_along(bib)) {
40-
authors <- paste0(unlist(bib[[i]]$author$family), collapse = '')
41-
if (authors == "")
42-
authors <- paste0(unlist(bib[[i]]$editor$family), collapse = '')
43-
if (authors == "")
44-
authors <- paste0(unlist(bib[[i]]$translator$family), collapse = '')
45-
if (authors == "")
46-
authors <- cleanupLatex(bib[[i]]$title)
47-
if (!length(authors))
48-
authors <- ""
49-
result[i] <- authors
50-
}
51-
result
52-
}
53-
54-
sortKeysV <- function(bib){
55-
result <- numeric(length(bib))
56-
for (i in seq_along(bib)){
57-
res <- bib[[i]]$volume
58-
if (!length(res)){
59-
res <- '0000'
60-
}else{
61-
tmp <- try(sprintf("%04d", as.numeric('res')), TRUE)
62-
if (!inherits(tmp, 'try-error'))
63-
res <- tmp
64-
}
65-
result[i] <- res
66-
}
67-
result
68-
}
69-
7037
#####################################################################################
7138
## FIELDS:
7239
#####################################################################################
7340

7441
fmtDate <- function(dat, ind = ''){
75-
if (length(dat)){
76-
paste0('(', DateFormatter(dat), ind, ').')
77-
}
42+
if (length(dat)){
43+
paste0('(', DateFormatter(dat), ind, ').')
44+
}
7845
}
7946

8047
fmtPages <- function(pgs, pref){

R/CommonFormatFuns.R

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ GetFormatFunctions <- function(docstyle = "text", DateFormatter){
9696
fmtAddOn <- cleanap
9797
fmtHowPublished <- cleanap
9898
fmtOtherField <- cleanap
99+
fmtVolumes <- label(suffix = ' vols.')
100+
fmtOrganization <- label(suffix = '.')
101+
99102

100103
fmtJTitle <- function(title){
101104
if (!is.null(title))
@@ -492,8 +495,56 @@ GetFormatFunctions <- function(docstyle = "text", DateFormatter){
492495
result
493496
}
494497

495-
fmtVolumes <- label(suffix = ' vols.')
496-
fmtOrganization <- label(suffix = '.')
498+
sortKeysLA <- function(bib, yrs){
499+
result <- character(length(bib))
500+
max.names <- .BibOptions$max.names
501+
for (i in seq_along(bib)) {
502+
res <- bib[[i]]$shorthand
503+
if (!length(res)){
504+
res <- bib[[i]]$label
505+
if (!length(res))
506+
res <- ProcessNamesLA(bib[[i]]$shortauthor, max.names)
507+
if (!length(res))
508+
res <- ProcessNamesLA(bib[[i]]$shorteditor, max.names)
509+
if (!length(res))
510+
res <- ProcessNamesLA(bib[[i]]$author, max.names)
511+
if (!length(res))
512+
res <- ProcessNamesLA(bib[[i]]$editor, max.names)
513+
if (!length(res))
514+
res <- ProcessNamesLA(bib[[i]]$translator, max.names)
515+
res <- paste0(res, substr(yrs[i], 3, 4))
516+
}
517+
result[i] <- res
518+
}
519+
result
520+
}
497521

522+
ProcessNamesLA <- function(nam, mn = .BibOptions$max.names){
523+
nam.len <- length(nam)
524+
if (nam.len){
525+
if (!inherits(nam, 'person'))
526+
nam <- ArrangeAuthors(nam)
527+
if (nam.len == 1){
528+
res <- paste0(nam$family, collapse = '')
529+
res <- regmatches(res,
530+
regexpr('[[:upper:]][[:punct:]]?[[:alpha:]][[:punct:]]?[[:alpha:]]',
531+
res, useBytes = TRUE))
532+
res <- gsub('[[:punct:]]', '', res, useBytes = TRUE)
533+
}else if (nam.len == 2 || nam.len == 3){
534+
res <- sapply(nam$family, paste0, collapse = '')
535+
res <- paste0(regmatches(res, regexpr('[[:upper:]]', res, useBytes = TRUE)),
536+
collapse = '')
537+
}else{
538+
res <- paste0(nam$family[[1]], collapse = '')
539+
res <- regmatches(res,
540+
regexpr('[[:upper:]][[:punct:]]?[[:alpha:]][[:punct:]]?[[:alpha:]]',
541+
res, useBytes = TRUE))
542+
res <- gsub('[[:punct:]]', '', res, useBytes = TRUE)
543+
res <- paste0(res, '+')
544+
}
545+
res
546+
}
547+
}
548+
498549
environment()
499550
}

0 commit comments

Comments
 (0)