aboutsummaryrefslogtreecommitdiff
path: root/include/filepath.h
blob: be148b1050a9153fddabd92b6637b3e6666456aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef NEWSBOAT_FILEPATH_H_
#define NEWSBOAT_FILEPATH_H_

#include "libnewsboat-ffi/src/filepath.rs.h"
#include "3rd-party/optional.hpp"

#include <ostream>
#include <string>

namespace newsboat {

/// A path in the file system.
///
/// This is a thin wrapper over Rust's `PathBuf`. The interface also mimics
/// that of `PathBuf`, for ease of migration.
/// https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html
class Filepath {
public:
#ifdef ENABLE_IMPLICIT_FILEPATH_CONVERSIONS
	// FIXME: remove these once the codebase is fully migrated from std::string
	// to Filepath

	Filepath(const char* input)
		: rs_object(std::move(Filepath::from_locale_string(std::string(input)).rs_object))
	{
	}

	Filepath(const std::string& input)
		: rs_object(std::move(Filepath::from_locale_string(input).rs_object))
	{
	}

	operator std::string() const
	{
		return to_locale_string();
	}
#endif

	Filepath(rust::Box<filepath::bridged::PathBuf>&& rs_object)
		: rs_object(std::move(rs_object))
	{
	}

	operator const filepath::bridged::PathBuf& () const
	{
		return *rs_object;
	}

	/// Constructs an empty path.
	Filepath();

	/// Constructs a filepath from string in locale encoding.
	///
	/// \note This does not perform any canonicalization, i.e. it does nothing
	/// to tilde (~), repeated path separators (path///to/file), symbolic links
	/// etc.
	static Filepath from_locale_string(const std::string&);

	Filepath(Filepath&&) = default;
	Filepath& operator=(Filepath&&) = default;

	Filepath(const Filepath& filepath);
	Filepath& operator=(const Filepath& filepath);

	bool operator==(const Filepath&) const;
	bool operator!=(const Filepath&) const;

	/// Returns the filepath as a string in locale encoding.
	///
	/// This is just bytes showed into `std::string`, no conversions are
	/// performed.
	std::string to_locale_string() const;

	/// Returns the filepath interpreted as UTF-8 string, with U+FFFD
	/// REPLACEMENT CHARACTER for any non-Unicode data.
	std::string display() const;

	/// Extends this path with a new component.
	///
	/// If component is an absolute path, it replaces the current path.
	void push(const Filepath& component);

	/// Creates a new Filepath with a given component appended to the current
	/// path (with a separator in between).
	Filepath join(const Filepath& component) const;

	// Return `true` if path is absolute.
	bool is_absolute() const;

	// Return `false` and do nothing if Filepath is empty, set extension and
	// return `true` otherwise.
	//
	// \note `ext` is interpreted as bytes in locale encoding.
	bool set_extension(const std::string& ext);

	// Return `true` if Filepath start with `base`, `false` otherwise.
	//
	// Only considers whole path components to match, i.e. "/foo" is **not**
	// a prefix of "/foobar/baz".
	bool starts_with(const Filepath& base) const;

	/// Returns the final component of the path, if there is one.
	nonstd::optional<Filepath> file_name() const;

private:
	rust::Box<filepath::bridged::PathBuf> rs_object;
};

} // namespace newsboat

// Used in Catch2's INFO macro.
inline std::ostream& operator<<(std::ostream& out, const newsboat::Filepath& p)
{
	out << p.display();
	return out;
}

#ifdef ENABLE_IMPLICIT_FILEPATH_CONVERSIONS
inline bool operator==(const std::string& lhs, const newsboat::Filepath& rhs)
{
	return lhs == rhs.to_locale_string();
}

#include "3rd-party/optional.hpp"
inline bool operator==(const nonstd::optional<std::string>& lhs,
	const newsboat::Filepath& rhs)
{
	return lhs && lhs.value() == rhs;
}
#endif

#endif /* NEWSBOAT_FILEPATH_H_ */
alue='wip-mdx-to-astro-js'>wip-mdx-to-astro-js Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/prefetch/test (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2022-07-08[ci] formatGravatar tony-sull 1-3/+3
2022-07-08fix: Always add @astrojs/image to vite.ssr.noExternal (#3869)Gravatar Tony Sullivan 2-0/+8
* fix: always add @astrojs/image to vite.ssr.noExternal * chore: add changeset
2022-07-08Format astro files in examples (#3862)Gravatar Marcus Otterström 73-694/+957
2022-07-08Integration README fixes (#3865)Gravatar Chris Swithinbank 8-8/+17
* Remove stray XML tag in sitemap integration README * Fix link errors * Add changeset
2022-07-08fix(#3843): move @babel/types to dependencies (#3863)Gravatar Nate Moore 2-2/+2
* fix(#3843): move @babel/types to dependencies * chore: update lockfile Co-authored-by: Nate Moore <nate@astro.build>
2022-07-08Fixed broken Markdown link (#3868)Gravatar Isaac McFadyen 1-2/+2
2022-07-08chore: bump Vite minimum version (#3861)Gravatar Nate Moore 2-2/+2
Co-authored-by: Nate Moore <nate@astro.build>
2022-07-08[ci] formatGravatar matthewp 1-1/+1
2022-07-08Better response.arrayBuffer() handling in Node (#3860)Gravatar Matthew Phillips 8-3/+125
* Better response.arrayBuffer() handling in Node * Adds a changeset
2022-07-08[ci] update lockfile (#3858)Gravatar Fred K. Bot 1-411/+437
Co-authored-by: FredKSchott <FredKSchott@users.noreply.github.com>
2022-07-08Fix manual import (#3857)Gravatar Chris Williams 1-1/+1
2022-07-07[ci] formatGravatar bholmesdev 1-3/+3
2022-07-07Docs: add adapter heading for configuration docs (#3842)Gravatar Ben Holmes 2-4/+20
* Docs: add adapter heading for configuration docs * docs: add adapter example, rework doc links * chore: changeset
2022-07-07[ci] formatGravatar natemoo-re 2-3/+3
2022-07-07fix: lint failing on astro and some integrations (#3794)Gravatar Joaquín Sánchez 7-17/+18
* fix: lint failing on astro and some integrations * chore: fix telemetry lint * chore: fix turbo cache (thx nate) * chore: fix runtime server
2022-07-07update solid peer dependenciesGravatar Fred K. Schott 2-1/+6
2022-07-07update lockfile (#3828)Gravatar Fred K. Schott 3-7/+1
2022-07-07Improve JSX definitions (#3801)Gravatar Erika 2-477/+858
2022-07-07Fix slot attribute inside expressions (#3837)Gravatar Nate Moore 8-5/+89
* fix: use slots inside expressions * test: add test for conditional named slots * test: fix incorrect test fixture * chore: update `@astrojs/compiler` * chore: add test coverage for `switch` Co-authored-by: Nate Moore <nate@astro.build>
2022-07-07[ci] formatGravatar FredKSchott 1-2/+1
2022-07-07detect package manager and improve types (#3847)Gravatar Fred K. Schott 7-44/+78
2022-07-07small create-astro wording changes (#3831)Gravatar Fred K. Schott 3-10/+15
2022-07-07Upgrade to pnpm@7.4.1, remove `patch-package` (#3747)Gravatar Nate Moore 6-127/+100
* chore: upgrade to pnpm@7.4.0, remove `patch-package` * chore: update contributing * chore: pnpm@7.4.1 * chore: bump to pnpm@7.5.0 Co-authored-by: Nate Moore <nate@astro.build>
2022-07-07[ci] formatGravatar matthewp 1-1/+1
2022-07-07Allow importing Image component from @astrojs/image (#3848)Gravatar Matthew Phillips 7-6/+20
* Allow importing Image component from @astrojs/image * Adds a changeset * Export the Image type
2022-07-06[ci] release (#3818)astro@1.0.0-beta.64@astrojs/telemetry@0.2.4@astrojs/node@0.1.4Gravatar Fred K. Bot 41-90/+90
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-07-07[ci] formatGravatar bholmesdev 1-1/+1
2022-07-06Fix: Infer content type with charset in dev and prod (#3841)Gravatar Ben Holmes 4-3/+23
* fix: add text/plain;charset;utf-8 header in dev * test: ensure content type for body shorthand * chore: changeset * feat: infer content type by pathname * feat: add charset to prod build handler * test: update for charset in prod build test
2022-07-06[ci] formatGravatar bholmesdev 1-2/+2
2022-07-06Fix `client:visible` directive in safari (#3839)Gravatar Ben Holmes 2-2/+20
* fix: client visible on safari * chore: changeset * refactor: wait for children with mutation observer * fix: remove unecessary settimeout * refactor: remove unecessary awaits
2022-07-06[ci] formatGravatar matthewp 1-1/+1
2022-07-06Ensure that maybeRenderHead runs last (#3821)Gravatar Matthew Phillips 5-8/+67
* Ensure that maybeRenderHead runs last * Adds a changeset * Make work with MDX
2022-07-05Fix portfolio example to use lowercase srcset (#3829)Gravatar Matthew Phillips 1-1/+1
2022-07-05[ci] formatGravatar delucis 1-29/+29