Skip to content

Commit

Permalink
Improve the time complexity to O(n) and use cpj_string_t as the param…
Browse files Browse the repository at this point in the history
…eter passing for APIs
  • Loading branch information
lygstate committed Dec 17, 2024
1 parent 333c2fa commit 1d62aba
Show file tree
Hide file tree
Showing 16 changed files with 1,281 additions and 2,464 deletions.
4 changes: 4 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MD013": false,
"MD024": false
}
23 changes: 2 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9.2)
cmake_minimum_required(VERSION 3.10)

# set project name
project(cpj
Expand Down Expand Up @@ -175,6 +175,7 @@ if(ENABLE_TESTS)
create_test(DEFAULT normalize mixed)
create_test(DEFAULT normalize overlap)
create_test(DEFAULT normalize empty)
create_test(DEFAULT normalize zero_length)
create_test(DEFAULT normalize only_separators)
create_test(DEFAULT normalize back_after_root)
create_test(DEFAULT normalize forward_slashes)
Expand Down Expand Up @@ -213,25 +214,6 @@ if(ENABLE_TESTS)
create_test(DEFAULT root change_separators)
create_test(DEFAULT root change_overlapping)
create_test(DEFAULT root change_without_root)
create_test(DEFAULT segment first)
create_test(DEFAULT segment last)
create_test(DEFAULT segment next)
create_test(DEFAULT segment next_too_far)
create_test(DEFAULT segment previous_absolute)
create_test(DEFAULT segment previous_relative)
create_test(DEFAULT segment previous_absolute_one_char_first)
create_test(DEFAULT segment previous_relative_one_char_first)
create_test(DEFAULT segment previous_too_far)
create_test(DEFAULT segment previous_too_far_root)
create_test(DEFAULT segment type)
create_test(DEFAULT segment back_with_root)
create_test(DEFAULT segment change_simple)
create_test(DEFAULT segment change_first)
create_test(DEFAULT segment change_last)
create_test(DEFAULT segment change_trim)
create_test(DEFAULT segment change_empty)
create_test(DEFAULT segment change_with_separator)
create_test(DEFAULT segment change_overlap)
create_test(DEFAULT windows get_root)
create_test(DEFAULT windows get_unc_root)
create_test(DEFAULT windows get_root_separator)
Expand All @@ -255,7 +237,6 @@ if(ENABLE_TESTS)
"${TEST_DIRECTORY}/normalize_test.c"
"${TEST_DIRECTORY}/relative_test.c"
"${TEST_DIRECTORY}/root_test.c"
"${TEST_DIRECTORY}/segment_test.c"
"${TEST_DIRECTORY}/windows_test.c")
enable_warnings(cpjtest)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

This is a lighweight C path manipulation library. It is currently compiled and
tested under **Linux**, **FreeBSD**, **Windows** and **MacOS**. It supports UNIX and Windows
path styles on all platforms.
path styles on all platforms. This is a fork of [cwalk](https://github.com/likle/cwalk)

## Features

Expand Down
62 changes: 0 additions & 62 deletions docs/reference/cwk_path_has_extension.md

This file was deleted.

63 changes: 35 additions & 28 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,103 @@ description: A complete reference of the cpj path library for C/C++.
---

## Basics

These are some basic, helpful functions available in the library. The basename is the last portion of the path which determines the name of the file or folder which is being pointed to. For instance, the path ``/var/log/test.txt`` would have the basename ``test.txt``. The dirname is the opposite - the path up to the basename. In that example the dirname would be ``/var/log``.

### Functions
* **[cpj_path_get_basename_test]({{ site.baseurl }}{% link reference/cpj_path_get_basename_test.md %})**

* **[cpj_path_get_basename_test]({{ site.baseurl }}{% link reference/cpj_path_get_basename_test.md %})**
Gets the basename of a file path.

* **[cpj_path_change_basename_test]({{ site.baseurl }}{% link reference/cpj_path_change_basename_test.md %})**
* **[cpj_path_change_basename_test]({{ site.baseurl }}{% link reference/cpj_path_change_basename_test.md %})**
Changes the basename of a file path.

* **[cpj_path_get_dirname_test]({{ site.baseurl }}{% link reference/cpj_path_get_dirname_test.md %})**
* **[cpj_path_get_dirname_test]({{ site.baseurl }}{% link reference/cpj_path_get_dirname_test.md %})**
Gets the dirname of a file path.

* **[cpj_path_get_root]({{ site.baseurl }}{% link reference/cpj_path_get_root.md %})**
* **[cpj_path_get_root]({{ site.baseurl }}{% link reference/cpj_path_get_root.md %})**
Determines the root of a path.

* **[cpj_path_change_root_test]({{ site.baseurl }}{% link reference/cpj_path_change_root_test.md %})**
* **[cpj_path_change_root_test]({{ site.baseurl }}{% link reference/cpj_path_change_root_test.md %})**
Changes the root of a path.

* **[cpj_path_is_absolute]({{ site.baseurl }}{% link reference/cpj_path_is_absolute.md %})**
* **[cpj_path_is_absolute]({{ site.baseurl }}{% link reference/cpj_path_is_absolute.md %})**
Determine whether the path is absolute or not.

* **[cpj_path_is_relative]({{ site.baseurl }}{% link reference/cpj_path_is_relative.md %})**
* **[cpj_path_is_relative]({{ site.baseurl }}{% link reference/cpj_path_is_relative.md %})**
Determine whether the path is relative or not.

* **[cpj_path_join_test]({{ site.baseurl }}{% link reference/cpj_path_join_test.md %})**
* **[cpj_path_join_test]({{ site.baseurl }}{% link reference/cpj_path_join_test.md %})**
Joins two paths together.

* **[cpj_path_join_multiple_test]({{ site.baseurl }}{% link reference/cpj_path_join_multiple_test.md %})**
* **[cpj_path_join_multiple_test]({{ site.baseurl }}{% link reference/cpj_path_join_multiple_test.md %})**
Joins multiple paths together.

* **[cpj_path_normalize_test]({{ site.baseurl }}{% link reference/cpj_path_normalize_test.md %})**
* **[cpj_path_normalize_test]({{ site.baseurl }}{% link reference/cpj_path_normalize_test.md %})**
Creates a normalized version of the path.

* **[cpj_path_intersection]({{ site.baseurl }}{% link reference/cpj_path_intersection.md %})**
* **[cpj_path_intersection]({{ site.baseurl }}{% link reference/cpj_path_intersection.md %})**
Finds common portions in two paths.

## Navigation

One might specify paths containing relative components ``../``. These functions help to resolve or create relative paths based on a base path.

### Functions
* **[cpj_path_get_absolute_test]({{ site.baseurl }}{% link reference/cpj_path_get_absolute_test.md %})**

* **[cpj_path_get_absolute_test]({{ site.baseurl }}{% link reference/cpj_path_get_absolute_test.md %})**
Generates an absolute path based on a base.

* **[cpj_path_get_relative_test]({{ site.baseurl }}{% link reference/cpj_path_get_relative_test.md %})**
* **[cpj_path_get_relative_test]({{ site.baseurl }}{% link reference/cpj_path_get_relative_test.md %})**
Generates a relative path based on a base.

## Extensions

Extensions are the portion of a path which come after a `.`. For instance, the file extension of the ``/var/log/test.txt`` would be ``.txt`` - which indicates that the content is text.

### Functions
* **[cpj_path_get_extension_test]({{ site.baseurl }}{% link reference/cpj_path_get_extension_test.md %})**
Gets the extension of a file path.

* **[cpj_path_has_extension_test]({{ site.baseurl }}{% link reference/cpj_path_has_extension_test.md %})**
Determines whether the file path has an extension.
* **[cpj_path_get_extension]({{ site.baseurl }}{% link reference/cpj_path_get_extension.md %})**
Gets the extension of a file path.

* **[cpj_path_change_extension_test]({{ site.baseurl }}{% link reference/cpj_path_change_extension_test.md %})**
* **[cpj_path_change_extension_test]({{ site.baseurl }}{% link reference/cpj_path_change_extension_test.md %})**
Changes the extension of a file path.

## Segments

A segment represents a single component of a path. For instance, on linux a path might look like this ``/var/log/``, which consists of two segments ``var`` and ``log``.

### Functions
* **[cpj_path_get_first_segment]({{ site.baseurl }}{% link reference/cpj_path_get_first_segment.md %})**

* **[cpj_path_get_first_segment]({{ site.baseurl }}{% link reference/cpj_path_get_first_segment.md %})**
Gets the first segment of a path.

* **[cpj_path_get_last_segment]({{ site.baseurl }}{% link reference/cpj_path_get_last_segment.md %})**
* **[cpj_path_get_last_segment]({{ site.baseurl }}{% link reference/cpj_path_get_last_segment.md %})**
Gets the last segment of the path.

* **[cpj_path_get_next_segment]({{ site.baseurl }}{% link reference/cpj_path_get_next_segment.md %})**
* **[cpj_path_get_next_segment]({{ site.baseurl }}{% link reference/cpj_path_get_next_segment.md %})**
Advances to the next segment.

* **[cpj_path_get_previous_segment]({{ site.baseurl }}{% link reference/cpj_path_get_previous_segment.md %})**
* **[cpj_path_get_previous_segment]({{ site.baseurl }}{% link reference/cpj_path_get_previous_segment.md %})**
Moves to the previous segment.

* **[cpj_path_get_segment_type]({{ site.baseurl }}{% link reference/cpj_path_get_segment_type.md %})**
* **[cpj_path_get_segment_type]({{ site.baseurl }}{% link reference/cpj_path_get_segment_type.md %})**
Gets the type of the submitted path segment.

* **[cpj_path_change_segment]({{ site.baseurl }}{% link reference/cpj_path_change_segment.md %})**
* **[cpj_path_change_segment]({{ site.baseurl }}{% link reference/cpj_path_change_segment.md %})**
Changes the content of a segment.

## Style

The path style describes how paths are generated and parsed. **cpj** currently supports two path styles, ``CPJ_STYLE_WINDOWS`` and ``CPJ_STYLE_UNIX``.

### Functions
* **[cpj_path_guess_style_test]({{ site.baseurl }}{% link reference/cpj_path_guess_style_test.md %})**

* **[cpj_path_guess_style]({{ site.baseurl }}{% link reference/cpj_path_guess_style.md %})**
Guesses the path style.

* **[cpj_path_set_style]({{ site.baseurl }}{% link reference/cpj_path_set_style.md %})**
* **[cpj_path_set_style]({{ site.baseurl }}{% link reference/cpj_path_set_style.md %})**
Configures which path style is used.

* **[cpj_path_get_style]({{ site.baseurl }}{% link reference/cpj_path_get_style.md %})**
Gets the path style configuration.
* **[cpj_path_get_style]({{ site.baseurl }}{% link reference/cpj_path_get_style.md %})**
Gets the path style configuration.
Loading

0 comments on commit 1d62aba

Please sign in to comment.