Line data Source code
1 : /*
2 : * Copyright (c) 2025 Project CHIP Authors
3 : *
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 : #include <app/persistence/String.h>
17 :
18 : namespace chip::app::Storage::Internal {
19 :
20 29 : bool ShortString::SetContent(CharSpan value)
21 : {
22 :
23 29 : ShortPascalString view = AsPascal();
24 :
25 29 : if (!view.SetValue(value))
26 : {
27 1 : view.SetValue(""_span);
28 1 : NullTerminate();
29 1 : return false;
30 : }
31 28 : NullTerminate();
32 28 : return true;
33 : }
34 :
35 4 : bool ShortStringInputAdapter::FinalizeRead(ByteSpan actuallyRead)
36 : {
37 4 : if (!ShortPascalString::IsValid(actuallyRead))
38 : {
39 1 : mValue.SetContent(""_span);
40 1 : return false;
41 : }
42 3 : mValue.NullTerminate();
43 3 : return true;
44 : }
45 :
46 : } // namespace chip::app::Storage::Internal
|