MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
Quoter.h
1/* miktex/Core/Quoter.h: -*- C++ -*-
2
3 Copyright (C) 1996-2021 Christian Schenk
4
5 This file is part of the MiKTeX Core Library.
6
7 The MiKTeX Core Library is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 The MiKTeX Core Library is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with the MiKTeX Core Library; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#pragma once
23
24#if !defined(CEFA448433DD489882E2BFB307C48DD9)
25#define CEFA448433DD489882E2BFB307C48DD9
26
27#include <miktex/Core/config.h>
28
29#include <string>
30
31#include <miktex/Util/CharBuffer>
32#include <miktex/Util/PathName>
34
35MIKTEX_CORE_BEGIN_NAMESPACE;
36
37template<typename CharType> class Quoter :
38 public MiKTeX::Util::CharBuffer<CharType>
39{
40public:
41 Quoter() = delete;
42
43public:
44 Quoter(const Quoter& other) = delete;
45
46public:
47 Quoter& operator=(const Quoter& other) = delete;
48
49public:
50 Quoter(Quoter&& other) = delete;
51
52public:
53 Quoter& operator= (Quoter&& other) = delete;
54
55public:
56 ~Quoter() = default;
57
58public:
59 explicit Quoter(const CharType* lpsz)
60 {
61 Quote(lpsz);
62 }
63
64public:
65 explicit Quoter(const std::basic_string<CharType>& s)
66 {
67 Quote(s.c_str());
68 }
69
70public:
71 explicit Quoter(const MiKTeX::Util::PathName& path)
72 {
73 Quote(path.GetData());
74 }
75
76private:
77 void Quote(const CharType* lpsz)
78 {
79 bool needQuotes = (*lpsz == 0 || MiKTeX::Util::StrChr(lpsz, 0x20/*' '*/) != nullptr);
80 if (needQuotes)
81 {
82 MiKTeX::Util::CharBuffer<CharType>::Append(0x22/*'"'*/);
83 }
84 MiKTeX::Util::CharBuffer<CharType>::Append(lpsz);
85 if (needQuotes)
86 {
87 MiKTeX::Util::CharBuffer<CharType>::Append(0x22/*'"'*/);
88 }
89 }
90};
91
92MIKTEX_CORE_END_NAMESPACE;
93
94#endif
Instances of this class store characters.
Definition CharBuffer.h:30
Instances of this class can be used to store path names.
Definition PathName.h:64
Inline functions.