//Title: Sentence-Formatted List Output Proc
//Credit to: Jtgibson
//Contributed by: Jtgibson
/*
This is an improved version of my former ThingyList proc... and, most
importantly, it now has a better name!
*/
var/const/ARTICLE_DEFAULT = 0
var/const/ARTICLE_INDEFINITE = 1
var/const/ARTICLE_DEFINITE = 2
var/const/ARTICLE_NONE = -1
proc/list2sentence(list/L, and="and", article=ARTICLE_DEFAULT)
var/sentence = ""
var/separator = ","
if(!istype(L, /list)) L = list(L)
for(var/i = 1, i <= L.len, i++)
if(istype(L[i], /list))
separator = ";"
break
if(L.len > 1)
for(var/j = 1, j < L.len, j++)
if(istype(L[j], /list)) //automatically recurse lists of lists
sentence += list2sentence(L[j], and="and", article)
else
if(article == ARTICLE_NONE)
sentence += "\proper [L[j]][(L.len > 2 || \
(L.len > 1 && article==ARTICLE_NONE)) ? separator : ""] "
else if(article == ARTICLE_INDEFINITE)
sentence += "\a [L[j]][(L.len > 2 || \
(L.len > 1 && article==ARTICLE_NONE)) ? separator : ""] "
else if(article == ARTICLE_DEFINITE)
sentence += "\the [L[j]][(L.len > 2 || \
(L.len > 1 && article==ARTICLE_NONE)) ? separator : ""] "
else
sentence += "[L[j]][L.len > 2 ? separator : ""] "
if(L.len)
if(L.len > 1 && article != ARTICLE_NONE)
sentence += "[and] "
if(istype(L[L.len], /list))
sentence += list2sentence(L[L.len], and="and", article)
else
if(article == ARTICLE_NONE)
sentence += "\proper [L[L.len]]"
else if(article == ARTICLE_INDEFINITE)
sentence += "\a [L[L.len]]"
else if(article == ARTICLE_DEFINITE)
sentence += "\the [L[L.len]]"
else
sentence += "[L[L.len]]"
return sentence
ID:195110
Nov 21 2006, 8:17 am
|
|