Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
Resource.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
7
8#include "Resource.h"
9
10using namespace Stroika::Foundation;
14using namespace Stroika::Foundation::DataExchange::XML;
15using namespace Stroika::Foundation::DataExchange::XML::Resource;
16
17using Memory::MakeSharedPtr;
18
19/*
20 ********************************************************************************
21 ********************************* Resource::Name *******************************
22 ********************************************************************************
23 */
24String Name::ToString () const
25{
27 sb << "{";
28 if (fNamespace) {
29 sb << "namespace: "sv << *fNamespace;
30 }
31 if (fPublicID) {
32 sb << ", PublicID: "sv << *fPublicID;
33 }
34 if (fSystemID) {
35 sb << ", systemID: "sv << *fSystemID;
36 }
37 if (sb.size () > 3) { // so a comma there
38 sb.ShrinkTo (sb.size () - 2); // lose comma
39 }
40 sb << "}"sv;
41 return sb;
42}
43
44/*
45 ********************************************************************************
46 ************************** Resource::MemoryResolver ****************************
47 ********************************************************************************
48 */
49ResolverPtr MemoryResolver::New (const Iterable<Definition>& defs)
50{
51 struct R final : IResolverRep {
52 R (const Iterable<Definition>& defs)
53 : fDefs_{defs}
54 {
55 }
56 virtual optional<Definition> Lookup (const Name& n) const override
57 {
58 // Treat namespaces and publicids as higher-priority matchers (because old code did in HealthFrame - but not sure of reason)
59 for (auto i : fDefs_) {
60 if (n.fNamespace != nullopt and n.fNamespace == i.fName.fNamespace) {
61 return i;
62 }
63 if (n.fPublicID != nullopt and n.fPublicID == i.fName.fPublicID) {
64 return i;
65 }
66 }
67 for (auto i : fDefs_) {
68 if (n.fSystemID != nullopt and n.fSystemID == i.fName.fSystemID) {
69 return i;
70 }
71 }
72 return nullopt;
73 }
75 };
76 return ResolverPtr{MakeSharedPtr<R> (defs)};
77}
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
nonvirtual size_t size() const noexcept
nonvirtual void ShrinkTo(size_t sz) noexcept
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition Iterable.h:237