Skip to content

Commit 08e51af

Browse files
committed
chore(): init
0 parents  commit 08e51af

File tree

8 files changed

+644
-0
lines changed

8 files changed

+644
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zz linguist-language=C++

.github/workflows/tests.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: 'Download ZZ'
16+
run: |
17+
git clone https://github.com/aep/zz.git
18+
- uses: actions-rs/cargo@v1
19+
with:
20+
command: install
21+
args: --path zz
22+
- name: 'Install System Dependencies'
23+
run: |
24+
sudo apt install -y z3
25+
- name: 'Tests'
26+
run: |
27+
zz test

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target
2+
.gdb_history
3+
vgcore.*
4+
**/*.o
5+
**/*.parsecache
6+
**/*.buildcache

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Joseph Werle
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
format
2+
======
3+
4+
> String format macros for ZZ
5+
6+
## Installation
7+
8+
Add this to your `zz.toml` file:
9+
10+
```toml
11+
[dependencies]
12+
format = "*"
13+
14+
[repos]
15+
format = "git://github.com/zzmodules/format"
16+
```
17+
18+
## Usage
19+
20+
```c++
21+
using format
22+
```
23+
24+
## API
25+
26+
### `@format::with(fmt, ...)`
27+
28+
Creates a formatted string from a variety of special tokens with traditional
29+
`printf` style specifiers supported.
30+
31+
### Tokens
32+
33+
* `{}` - Treats argument like a _struct_, calling `.display()` for a `char *`
34+
* `{*}` - Treats argument like a _pointer to a struct_, calling `->display()` for a `char *`
35+
* `{0..9}` - References argument by position. Treatment is the same as `{}`
36+
* `{*0..9}` - References pointer argument by position. Treatment is same as `{*}`
37+
* `{$0..9}` - References argument _identifier name_ by position and uses it inline
38+
* `{0..9%X}` - References argument by position with format. Treatment is like a limited `printf`
39+
40+
### `Display` Interface
41+
42+
The `@format::with()` macro will treat struct and struct pointers specified
43+
with `{}`, `{*}`, and its variant as special input that should implement a
44+
**displayable** interface. Structs should simply implement a
45+
`display() -> char *` method like in the example below:
46+
47+
```c++
48+
using format
49+
using log
50+
using string
51+
52+
struct Vector {
53+
float x;
54+
float y;
55+
}
56+
57+
fn display(Vector *self) -> char * {
58+
new+64000 out = string::make();
59+
out.format("Vector { x: %0.2f, y: %0.2f }", self->x, self->y);
60+
return out.cstr();
61+
}
62+
63+
fn main() -> {
64+
let vec = Vector { x: 1.23, y: 2.46 };
65+
log::info("%s", @format::with("{}", vec)); // Vector { x: 1.23, y: 2.46 }
66+
return 0;
67+
}
68+
```
69+
70+
## License
71+
72+
MIT

0 commit comments

Comments
 (0)