1
Fork 0
mirror of https://github.com/RGBCube/properties.v synced 2025-07-29 07:57:46 +00:00

Some uncompleted work

This commit is contained in:
RGBCube 2023-03-10 22:57:22 +03:00
commit 5b478a07aa
12 changed files with 301 additions and 0 deletions

9
.editorconfig Normal file
View file

@ -0,0 +1,9 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.v]
indent_style = tab
indent_size = 4

7
.gitattributes vendored Normal file
View file

@ -0,0 +1,7 @@
* text=auto eol=lf
*.bat eol=crlf
**/*.v linguist-language=V
**/*.vv linguist-language=V
**/*.vsh linguist-language=V
**/v.mod linguist-language=V

51
.github/workflows/deploy-docs.yml vendored Normal file
View file

@ -0,0 +1,51 @@
name: Deploy Docs
on: push
env:
project-name: properties
jobs:
deploy-docs:
runs-on: ubuntu-latest
steps:
- name: Set Up V
uses: vlang/setup-v@v1.1
with:
check-latest: true
- name: Checkout Repository
uses: actions/checkout@v3
- name: Checkout Site Repository
uses: actions/checkout@v3
with:
repository: RGBCube/rgbcube.github.io
path: site
- name: Generate Docs
run: |
mv ./src ./${{ env.project-name }}.v # For the docs header
cp ./README.md ./${{ env.project-name }}.v/ # For the README to be included in the docs.
v doc -readme -f html -o ./ -m ./${{ env.project-name }}.v
rm -rf ./site/docs/${{ env.project-name }} || true
mkdir -p ./site/docs/${{ env.project-name }}
cp -r ./_docs/* ./site/docs/${{ env.project-name }}/
- name: Add Private Key To SSH Agent
uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.RGBCUBE_GITHUB_IO_PRIVATE_KEY }}
- name: Push Docs To GitHub
continue-on-error: true
run: |
cd site
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
git add ./
git commit -m "Deploy ${{ env.project-name }}.v docs"
git push git@github.com:RGBCube/rgbcube.github.io master

20
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Test
on:
- pull_request
- push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set Up V
uses: vlang/setup-v@v1.1
with:
check-latest: true
- name: Checkout Repository
uses: actions/checkout@v3
- name: Test
run: v test ./

20
.github/workflows/verify-formatting.yml vendored Normal file
View file

@ -0,0 +1,20 @@
name: Verify Formatting
on:
- pull_request
- push
jobs:
verify-formatting:
runs-on: ubuntu-latest
steps:
- name: Set Up V
uses: vlang/setup-v@v1.1
with:
check-latest: true
- name: Checkout Repository
uses: actions/checkout@v3
- name: Verify That The Code Is Formatted
run: v fmt -verify ./

12
.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
main
properties
*.exe
*.exe~
*.so
*.dylib
*.dll
bin/
.DS_Store
.idea/
.vscode/
*.iml

21
LICENSE.md Normal file
View file

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

63
README.md Normal file
View file

@ -0,0 +1,63 @@
<div align="center">
<h1>properties.v</h1>
[Docs](https://rgbcube.github.io/docs/properties) | [Examples](https://github.com/RGBCube/properties.v/tree/master/examples)
Parse properties files in V.
</div>
## Installation
After doing these, you can use the module in your V programs by importing `rgbcube.properties`.
### Via VPM
```bash
v install RGBCube.properties
```
### Via Git
```bash
git clone https://github.com/RGBCube/properties.v ~/.vmodules/rgbcube/properties
```
## Example
```v
import rgbcube.properties
props := properties.parse_file('example.properties') or {
panic(err)
}
println(props['my.key.here'])
```
## License
```
MIT License
Copyright (c) 2022-present RGBCube
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

2
samples/test.properties Normal file
View file

@ -0,0 +1,2 @@
asdasd\\def = asdlnj\
asdasd\\n

81
src/properties.v Normal file
View file

@ -0,0 +1,81 @@
module properties
import os
import strings
// parse_file parses a properties file after reading it and returns a map of the key-value pairs.
pub fn parse_file(path string) !map[string]string {
return parse(os.read_file(path)!)
}
// parse parses a properties string and returns a map of the key-value pairs.
pub fn parse(raw string) map[string]string {
mut properties := map[string]string{}
mut current_raw_index := 0
mut current_ident := strings.new_builder(30)
mut current_value := strings.new_builder(30)
mut parsing_ident := true
for current_raw_index < raw.len {
match raw[current_raw_index] {
`#`, `!` {
// Ignore until we find a newline.
for raw[current_raw_index] !in [`\n`, `\r`] {
current_raw_index++
}
}
` `, `\t` {
if !parsing_ident {
current_value.write_rune(raw[current_raw_index])
}
}
`=`, `:` {
if parsing_ident {
parsing_ident = false
}
}
`\\` {
// if raw[current_raw_index + 1] or { `\0` } == `\\`
// || raw[current_raw_index - 1] == `\\` {
// if parsing_ident {
// current_ident.write_rune(`\\`)
// } else {
// current_value.write_rune(`\\`)
// }
// }
// Ignore until we find a newline.
for raw[current_raw_index] !in [`\n`, `\r`] {
current_raw_index++
}
}
`\n`, `\r` {
parsing_ident = true
if current_ident.len > 0 {
properties[current_ident.str()] = current_value.str().trim_space()
}
current_ident.clear()
current_value.clear()
}
else {
if !parsing_ident {
current_value.write_rune(raw[current_raw_index])
} else {
current_ident.write_rune(raw[current_raw_index])
}
}
}
current_raw_index++
}
// Handle cases where the file doesn't end with a newline.
if current_ident.len > 0 {
properties[current_ident.str()] = current_value.str().trim_space()
}
return properties
}

7
src/properties_test.v Normal file
View file

@ -0,0 +1,7 @@
module properties
fn test_properties_parse() ! {
props := parse_file('./samples/test.properties')!
println(props)
}

8
v.mod Normal file
View file

@ -0,0 +1,8 @@
Module {
name: 'properties'
description: 'Parse properties files in V.'
version: '0.0.1'
license: 'MIT'
repo_url: 'https://github.com/RGBCube/properties.v'
dependencies: []
}