Skip to content

Commit 0771de2

Browse files
first commit with implemented code and backbones
1 parent 3af3c05 commit 0771de2

34 files changed

+1463
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
project(Week1_ini_parse_Projects VERSION 0.1 LANGUAGES CXX)
3+
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
5+
set(CMAKE_BUILD_TYPE "Debug")
6+
7+
message(STATUS "Configuring the example utils sources for core")
8+
add_subdirectory(example_utils)
9+
message(STATUS "Configuring the example utils sources for core done")
10+
11+
add_subdirectory(string_splits)
12+
add_subdirectory(ini_parse)
13+
14+
add_subdirectory(example)
15+
add_subdirectory(test)
16+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_executable(example_ini example_ini.cpp)
2+
target_link_libraries(example_ini PRIVATE IniParser)
3+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "ini_parse.h"
2+
#include <cassert>
3+
#include <iostream>
4+
#include <string>
5+
6+
const char* sample = R"ini(
7+
; this is a comment
8+
# also a comment
9+
; top-level keys
10+
topkey = topvalue
11+
12+
[server]
13+
host = example.com
14+
port= 8080
15+
path = "/api/v1/resource" ; inline comment
16+
escaped = "line\nnew" # another inline comment
17+
18+
[database]
19+
user = dbuser
20+
password = "p@ss;word" ; note semicolon inside quoted value
21+
timeout=30
22+
23+
)ini";
24+
25+
int main() {
26+
using namespace cxx_utils::ini_parser;
27+
28+
IniParser parser;
29+
bool ok = parser.parse({ sample });
30+
assert(ok);
31+
32+
for (const auto& sec_pair : parser.data()) {
33+
std::cout << "[" << sec_pair.first << "]\n";
34+
for (const auto& kv : sec_pair.second) {
35+
std::cout << kv.first << " = " << kv.second << "\n";
36+
}
37+
std::cout << "\n";
38+
}
39+
40+
std::cout << "All tests passed.\n";
41+
return 0;
42+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_subdirectory(privates)
2+
3+
add_library(ExampleUtils STATIC banner.cpp)
4+
target_include_directories(ExampleUtils PUBLIC .)
5+
target_link_libraries(ExampleUtils PRIVATE ExampleUtilsPrivate)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "banner.h"
2+
#include "banner/banner_private.h"
3+
#include <cstddef>
4+
#include <sstream>
5+
#include <string_view>
6+
7+
namespace cxx_utils::example_utils {
8+
9+
std::string banner_src(std::string_view view,
10+
const BannerAlignment alignment,
11+
const char banner_ch) {
12+
const size_t str_length = view.length();
13+
const size_t banner_length = example_utils_private::expected_banner_length(view);
14+
const size_t banner_escape_length = example_utils_private::expected_left_escape(alignment);
15+
const std::string banners(banner_length, banner_ch);
16+
const std::string escape_left(banner_escape_length, ' ');
17+
18+
std::ostringstream banner_stream;
19+
banner_stream << banners << '\n'
20+
<< escape_left << view << '\n'
21+
<< banners << '\n';
22+
23+
return banner_stream.str();
24+
}
25+
26+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file banner.h
3+
* @author Charliechen114514 (chengh1922@mails.jlu.edu.cn)
4+
* @brief Banner Public Interfaces
5+
* @version 0.1
6+
* @date 2025-11-17
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#pragma once
13+
#include <string>
14+
#include <string_view>
15+
16+
namespace cxx_utils {
17+
namespace example_utils {
18+
/**
19+
* @brief BannerAlignment indicated the alignment of
20+
* string position
21+
*
22+
*/
23+
enum class BannerAlignment {
24+
LEFT,
25+
CENTER,
26+
RIGHT
27+
};
28+
29+
/**
30+
* @brief Create A String Sources for banner, you can use it to
31+
* Redirect to any IO
32+
*
33+
* @param view
34+
* @param alignment
35+
* @param banner_ch
36+
* @return std::string
37+
*/
38+
[[nodiscard("Don't Ignore the Return Value of"
39+
" Banner String, else why shell you create it :)")]]
40+
std::string banner_src(std::string_view view,
41+
const BannerAlignment alignment = BannerAlignment::CENTER,
42+
const char banner_ch = '=');
43+
}
44+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file example_utils.h
3+
* @author Charliechen114514 (chengh1922@mails.jlu.edu.cn)
4+
* @brief Summary Header for the Example Utilities
5+
* @version 0.1
6+
* @date 2025-11-17
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#pragma once
13+
#include "banner.h"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
message(STATUS "Configuring the ExampleUtilsPrivate")
2+
add_library(ExampleUtilsPrivate STATIC
3+
banner/banner_private.cpp
4+
banner/banner_private.h)
5+
6+
7+
target_include_directories(ExampleUtilsPrivate PUBLIC .)
8+
message(STATUS "Configuring the ExampleUtilsPrivate Done")
9+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "banner_private.h"
2+
3+
namespace cxx_utils::example_utils_private {
4+
std::size_t
5+
expected_banner_length(const std::string_view v) {
6+
return 2 * LENGTH_ESCAPE + v.length();
7+
}
8+
9+
std::size_t
10+
expected_left_escape(const example_utils::BannerAlignment alignment) {
11+
switch (alignment) {
12+
case example_utils::BannerAlignment::LEFT:
13+
return 0;
14+
case example_utils::BannerAlignment::CENTER:
15+
return LENGTH_ESCAPE;
16+
case example_utils::BannerAlignment::RIGHT:
17+
return 2 * LENGTH_ESCAPE;
18+
}
19+
return LENGTH_ESCAPE;
20+
}
21+
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "../banner.h"
3+
#include <cstddef>
4+
#include <string_view>
5+
namespace cxx_utils {
6+
namespace example_utils_private {
7+
8+
static constexpr const size_t LENGTH_ESCAPE = 5;
9+
10+
std::size_t
11+
expected_banner_length(const std::string_view v);
12+
13+
std::size_t
14+
expected_left_escape(const example_utils::BannerAlignment alignment);
15+
16+
}
17+
}

0 commit comments

Comments
 (0)