mirror of
https://github.com/likle/cwalk.git
synced 2026-10-28 09:44:01 +00:00
added cwk_path_guess_style
This commit is contained in:
1 parent
61cb036e6b
commit
b6b6bb92f1
12 files changed
+251
-7
No files matched your search
@@ -18,7 +18,7 @@ This function finds the first segment of a path. The position of the segment is
|
||||
* **path**: The path which will be inspected.
|
||||
* **segment**: The segment which will be extracted.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns ``true`` if there is a segment or ``false`` if there is none.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -17,7 +17,7 @@ This function gets the last segment of a path. This function may return false if
|
||||
* **path**: The path which will be inspected.
|
||||
* **segment**: The segment which will be extracted.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns ``true`` if there is a segment or ``false`` if there is none.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -16,7 +16,7 @@ This function advances the current segment to the next segment. If there are no
|
||||
## Parameters
|
||||
* **segment**: The current segment which will be advanced to the next one.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns ``true`` if another segment was found or ``false`` otherwise.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -16,7 +16,7 @@ This function moves the current segment to the previous segment. If the current
|
||||
## Parameters
|
||||
* **segment**: The current segment which will be moved to the previous one.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns ``true`` if there is a segment before this one or ``false`` otherwise.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -16,7 +16,7 @@ This function inspects the contents of the segment and determines the type of it
|
||||
## Parameters
|
||||
* **segment**: The segment which will be inspected.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns the type of the segment.
|
||||
|
||||
## Example
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
---
|
||||
title: cwk_path_guess_style
|
||||
description: Guesses the path style.
|
||||
---
|
||||
|
||||
_(since v1.2.0)_
|
||||
Guesses the path style.
|
||||
|
||||
## Description
|
||||
```c
|
||||
enum cwk_path_style cwk_path_guess_style(const char *path);
|
||||
```
|
||||
|
||||
This function guesses the path style based on a submitted path-string. The guessing will look at the root and the type of slashes contained in the path and return the style which is more likely used in the path.
|
||||
The algorithm checks the following:
|
||||
1. If the root is longer than 1 character -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a backslash -> ``CWK_STYLE_WINDOWS``
|
||||
1. If the first separator is a slash -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment starts with a dot -> ``CWK_STYLE_UNIX``
|
||||
1. If the last segment contains a dot -> ``CWK_STYLE_WINDOWS``
|
||||
1. If nothing was found to determine the style -> ``CWK_STYLE_UNIX``
|
||||
|
||||
## Parameters
|
||||
* **path**: The path which will be inspected.
|
||||
|
||||
## Return Value
|
||||
Returns the style which is most likely used for the path.
|
||||
|
||||
## Outcomes
|
||||
|
||||
| Path | Result |
|
||||
|-----------------------------|-----------------------|
|
||||
| ``C:\\test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``C:/folder/.test`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\directory\other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``\\directory\\.other`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``myfile.txt`` | ``CWK_STYLE_WINDOWS`` |
|
||||
| ``/directory`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/directory/other.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``.my_hidden_file.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``/a/directory/myfile.txt`` | ``CWK_STYLE_UNIX`` |
|
||||
| ``myfile`` | ``CWK_STYLE_UNIX`` |
|
||||
|
||||
## Example
|
||||
```c
|
||||
#include <cwalk.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (cwk_path_guess_style("C:\\myfile") == CWK_STYLE_UNIX) {
|
||||
printf("UNIX.");
|
||||
} else {
|
||||
printf("WINDOWS.");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
```
|
||||
|
||||
Ouput:
|
||||
```
|
||||
WINDOWS.
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|------------|--------------------------------------------------------|
|
||||
| **v1.2.0** | The function is introduced. |
|
||||
@@ -16,7 +16,7 @@ This function determines whether the submitted file path has an extension. This
|
||||
## Parameters
|
||||
* **path**: The path which will be inspected.
|
||||
|
||||
## Return Vaue
|
||||
## Return Value
|
||||
Returns ``true`` if the path has an extension or ``false`` otherwise.
|
||||
|
||||
## Outcomes
|
||||
|
||||
@@ -77,8 +77,11 @@ Gets the type of the submitted path segment.
|
||||
The path style describes how paths are generated and parsed. ``cwalk`` currently supports two path styles, ``CWK_STYLE_WINDOWS`` and ``CWK_STYLE_UNIX``.
|
||||
|
||||
### Functions
|
||||
* **[cwk_path_guess_style]({{ site.baseurl }}{% link reference/cwk_path_guess_style.md %})**
|
||||
Guesses the path style.
|
||||
|
||||
* **[cwk_path_set_style]({{ site.baseurl }}{% link reference/cwk_path_set_style.md %})**
|
||||
Configures which path style is used.
|
||||
|
||||
* **[cwk_path_get_style]({{ site.baseurl }}{% link reference/cwk_path_get_style.md %})**
|
||||
Gets the path style configuration..
|
||||
Gets the path style configuration.
|
||||
Reference in new issue
Block a user