我正在寻找一个解析Emacs Lisp中的整数列表的函数,与Perl的Set::IntSpan一致。即,我希望能够做到这样的事情:
.one-gallery ul {
list-style: none;
margin: 0;
padding: 0;
}
.one-gallery figure {
margin: 0;
}
.one-gallery figure img {
display: block;
width: 100%;
}
/* Grid style */
.grid-wrap {
max-width: 1400px;
margin: 0 auto;
}
.one-grid {
margin: 0 auto;
}
.one-grid li {
width: 24%;
float: left;
cursor: pointer;
}
.one-grid figure {
padding: 15px;
-webkit-transition: opacity 0.2s;
transition: opacity 0.2s;
}
在某处有一个elisp库吗?
答案 0 :(得分:1)
以下是您想要的:
$today = new DateTime();
// Day of the month, 2 digits with leading zeros
$day_today; = $today->format('d');
// OR
// Day of the month without leading zeros
$day_today; = $today->format('J');
// Last day of the given month in datetime
$last_day; = $today->format('t');
Choose day:<input type="number" min="<?php echo $day_today; ?>" max="<?php echo $last_day; ?>" />
代码循环传入的字符串,搜索普通数字或数字范围。在每次匹配时,它会调用(defun parse-integer-list (str)
"Parse string representing a range of integers into a list of integers."
(let (start ranges)
(while (string-match "\\([0-9]+\\)\\(?:-\\([0-9]+\\)\\)?" str start)
(push
(apply 'number-sequence
(seq-map 'string-to-int
(seq-filter
'identity
(list (match-string 1 str) (match-string 2 str)))))
ranges)
(setq start (match-end 0)))
(nreverse (seq-mapcat 'nreverse ranges))))
,只需要一个普通匹配的数字或一个范围匹配的两个数字,然后将每个结果的数字序列推送到一个列表中。为了考虑number-sequence
向后构建结果,最后它会反转列表中的所有范围,连接它们,然后反转结果并返回它。
使用您的示例输入调用push
:
parse-integer-list
产生
(parse-integer-list "1-3, 4, 8, 18-21")