diff options
author | mattn <mattn.jp@gmail.com> | 2014-10-30 15:03:26 +0900 |
---|---|---|
committer | mattn <mattn.jp@gmail.com> | 2014-10-30 15:03:26 +0900 |
commit | e5a9029a352ae215830333082e674f047250619e (patch) | |
tree | 471dc78c7441549f1f7b196374fa82b517829fd5 | |
parent | 42e3770909de7ae6628bb7656060ceb1993c5b4b (diff) | |
download | vim-sonictemplate-e5a9029a352ae215830333082e674f047250619e.tar.gz vim-sonictemplate-e5a9029a352ae215830333082e674f047250619e.tar.bz2 vim-sonictemplate-e5a9029a352ae215830333082e674f047250619e.zip |
Add sorter
-rw-r--r-- | template/go/snip-sorter.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/template/go/snip-sorter.go b/template/go/snip-sorter.go new file mode 100644 index 0000000..49fe7ac --- /dev/null +++ b/template/go/snip-sorter.go @@ -0,0 +1,13 @@ +func ({{_var_:varname}} {{_var_:name}}) Len() int { + return len({{_var_:varname}}) +} + +func ({{_var_:varname}} {{_var_:name}}) Less(i, j int) bool { + return {{_var_:varname}}[i] < {{_var_:varname}}[j] +} + +func ({{_var_:varname}} {{_var_:name}}) Swap(i, j int) { + {{_var_:varname}}[i], {{_var_:varname}}[j] = {{_var_:varname}}[j], {{_var_:varname}}[i] +} +{{_define_:name:input('name: ')}} +{{_define_:varname:substitute('{{_var_:name}}' =~ '^[ij]' ? '{{_var_:name}}'[:1] : '{{_var_:name}}'[0],'\w\+', '\l\0', '')}} |