Skip to content

Commit

Permalink
Project rearranged.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim2266 committed Mar 29, 2024
1 parent 2414c82 commit 847a221
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 62 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[Makefile]
indent_size = 8
14 changes: 0 additions & 14 deletions Makefile

This file was deleted.

27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,7 @@

Package `trw` wraps around various text processing functions from the standard
Go library to allow for functional composition of operations, also minimising
memory consumption.

### Example
```Go
func Example() {
src := []byte("*SomeSome* example _text_")
res := rewriter.Do(src)

fmt.Println(string(res))
// Output:
// <b>Some</b> example <i>text</i>
}

var rewriter = Seq(
Delete(LitN("Some", 1)),
Replace(Patt(`[[:space:]]+`), " "),
Expand(`_([^_]+)_`, `<i>${1}</i>`),
Expand(`\*([^\*]+)\*`, `<b>${1}</b>`),
)
```

### Installation

```sh
go get -u github.com/maxim2266/trw
```
memory consumption. [Here](example_test.go) is an example of usage.

### About the package

Expand Down
47 changes: 47 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (c) 2019,2020 Maxim Konakov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package trw

import "fmt"

func Example() {
src := []byte("*SomeSome* example _text_")
res := rewriter.Do(src)

fmt.Println(string(res))
// Output:
// <b>Some</b> example <i>text</i>
}

var rewriter = Seq(
Delete(LitN("Some", 1)),
Replace(Patt(`[[:space:]]+`), " "),
Expand(`_([^_]+)_`, `<i>${1}</i>`),
Expand(`\*([^\*]+)\*`, `<b>${1}</b>`),
)
2 changes: 0 additions & 2 deletions trw.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,3 @@ func ReN(re *regexp.Regexp, n int) Matcher {
return re.FindAllIndex(s, n)
}
}

/* vim: set ts=4 sw=4 tw=0 noet :*/
20 changes: 0 additions & 20 deletions trw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ package trw

import (
"bytes"
"fmt"
"testing"
)

Expand Down Expand Up @@ -361,22 +360,3 @@ func max(a, b int) int {

return b
}

// example
func _Example() {
src := []byte("*SomeSome* example _text_")
res := rewriter.Do(src)

fmt.Println(string(res))
// Output:
// <b>Some</b> example <i>text</i>
}

var rewriter = Seq(
Delete(LitN("Some", 1)),
Replace(Patt(`[[:space:]]+`), " "),
Expand(`_([^_]+)_`, `<i>${1}</i>`),
Expand(`\*([^\*]+)\*`, `<b>${1}</b>`),
)

/* vim: set ts=4 sw=4 tw=0 noet :*/

0 comments on commit 847a221

Please sign in to comment.