Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Resource.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include "Resource.h"
7
8using namespace Stroika::Foundation;
12using namespace Stroika::Foundation::DataExchange::XML;
13using namespace Stroika::Foundation::DataExchange::XML::Resource;
14
15/*
16 ********************************************************************************
17 ********************************* Resource::Name *******************************
18 ********************************************************************************
19 */
20String Name::ToString () const
21{
23 sb << "{";
24 if (fNamespace) {
25 sb << "namespace: "sv << *fNamespace;
26 }
27 if (fPublicID) {
28 sb << ", PublicID: "sv << *fPublicID;
29 }
30 if (fSystemID) {
31 sb << ", systemID: "sv << *fSystemID;
32 }
33 if (sb.size () > 3) { // so a comma there
34 sb.ShrinkTo (sb.size () - 2); // lose comma
35 }
36 sb << "}"sv;
37 return sb;
38}
39
40/*
41 ********************************************************************************
42 ************************** Resource::MemoryResolver ****************************
43 ********************************************************************************
44 */
45ResolverPtr MemoryResolver::New (const Iterable<Definition>& defs)
46{
47 struct R : IResolverRep {
48 R (const Iterable<Definition>& defs)
49 : fDefs_{defs}
50 {
51 }
52 virtual optional<Definition> Lookup (const Name& n) const override
53 {
54 // Treat namespaces and publicids as higher-priority matchers (because old code did in HealthFrame - but not sure of reason)
55 for (auto i : fDefs_) {
56 if (n.fNamespace != nullopt and n.fNamespace == i.fName.fNamespace) {
57 return i;
58 }
59 if (n.fPublicID != nullopt and n.fPublicID == i.fName.fPublicID) {
60 return i;
61 }
62 }
63 for (auto i : fDefs_) {
64 if (n.fSystemID != nullopt and n.fSystemID == i.fName.fSystemID) {
65 return i;
66 }
67 }
68 return nullopt;
69 }
71 };
72 return ResolverPtr{make_shared<R> (defs)};
73}
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