Skip to content

Commit

Permalink
api: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Feb 2, 2024
1 parent 1474009 commit 92aeaf4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
28 changes: 28 additions & 0 deletions api/impl_flag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 The Jule Programming Language.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.

#ifndef __JULE_IMPL_FLAG_HPP
#define __JULE_IMPL_FLAG_HPP

#if __cplusplus == 199711L
#define __JULE_CPP98
#elif __cplusplus == 201103L
#define __JULE_CPP11
#elif __cplusplus == 201402L
#define __JULE_CPP14
#elif __cplusplus == 201703L
#define __JULE_CPP17
#elif __cplusplus == 202002L
#define __JULE_CPP20
#endif

#if defined(__JULE_CPP20)
#define __JULE_CONSTEXPR_SINCE_CPP20 constexpr
#define __JULE_INLINE_BEFORE_CPP20
#else
#define __JULE_CONSTEXPR_SINCE_CPP20
#define __JULE_INLINE_BEFORE_CPP20 inline
#endif

#endif // ifndef __JULE_IMPL_FLAG_HPP
1 change: 1 addition & 0 deletions api/jule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIGURATION DEFINES
#ifndef __JULE_HPP
#define __JULE_HPP

#include "impl_flag.hpp"
#include "derive/derive.hpp"
#include "any.hpp"
#include "array.hpp"
Expand Down
17 changes: 9 additions & 8 deletions api/str.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cstring>
#include <vector>

#include "impl_flag.hpp"
#include "panic.hpp"
#include "utf8.hpp"
#include "utf16.hpp"
Expand Down Expand Up @@ -63,22 +64,22 @@ namespace jule
typedef jule::U8 *Iterator;
typedef const jule::U8 *ConstIterator;

constexpr Iterator begin(void) noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 Iterator begin(void) noexcept
{
return static_cast<Iterator>(&this->buffer[0]);
}

constexpr ConstIterator begin(void) const noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 ConstIterator begin(void) const noexcept
{
return static_cast<ConstIterator>(&this->buffer[0]);
}

constexpr Iterator end(void) noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 Iterator end(void) noexcept
{
return static_cast<Iterator>(&this->buffer[this->len()]);
}

constexpr ConstIterator end(void) const noexcept
inline ConstIterator end(void) const noexcept
{
return static_cast<ConstIterator>(&this->buffer[this->len()]);
}
Expand Down Expand Up @@ -136,12 +137,12 @@ namespace jule
0, this->len());
}

constexpr jule::Int len(void) const noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 jule::Int len(void) const noexcept
{
return this->buffer.length();
return static_cast<jule::Int>(this->buffer.length());
}

constexpr jule::Bool empty(void) const noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 jule::Bool empty(void) const noexcept
{
return this->buffer.empty();
}
Expand Down Expand Up @@ -192,7 +193,7 @@ namespace jule

// Returns element by index.
// Not includes safety checking.
constexpr jule::U8 &__at(const jule::Int &index) noexcept
__JULE_INLINE_BEFORE_CPP20 __JULE_CONSTEXPR_SINCE_CPP20 jule::U8 &__at(const jule::Int &index) noexcept
{
return this->buffer[index];
}
Expand Down

0 comments on commit 92aeaf4

Please sign in to comment.