1 //===-- runtime/character.cpp -----------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "character.h"
10 #include "terminator.h"
11 #include <algorithm>
12 #include <cstring>
13 
14 namespace Fortran::runtime {
15 extern "C" {
16 
17 void RTNAME(CharacterConcatenate)(Descriptor & /*temp*/,
18     const Descriptor & /*operand*/, const char * /*sourceFile*/,
19     int /*sourceLine*/) {
20   // TODO
21 }
22 
23 void RTNAME(CharacterConcatenateScalar)(
24     Descriptor & /*temp*/, const char * /*from*/, std::size_t /*byteLength*/) {
25   // TODO
26 }
27 
28 void RTNAME(CharacterAssign)(Descriptor & /*lhs*/, const Descriptor & /*rhs*/,
29     const char * /*sourceFile*/, int /*sourceLine*/) {
30   // TODO
31 }
32 
33 std::size_t RTNAME(CharacterAppend)(char *lhs, std::size_t lhsLength,
34     std::size_t offset, const char *rhs, std::size_t rhsLength) {
35   if (auto n{std::min(lhsLength - offset, rhsLength)}) {
36     std::memcpy(lhs + offset, rhs, n);
37     offset += n;
38   }
39   return offset;
40 }
41 
42 void RTNAME(CharacterPad)(char *lhs, std::size_t length, std::size_t offset) {
43   if (length > offset) {
44     std::memset(lhs + offset, ' ', length - offset);
45   }
46 }
47 }
48 } // namespace Fortran::runtime
49