Changeset b08a62c in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
79f35d40
Parents:
836ecad
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-25 21:36:10)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: added implementation of the most basic string functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/string.hpp

    r836ecad rb08a62c  
    320320             */
    321321
    322             iterator begin() noexcept;
    323 
    324             const_iterator begin() const noexcept;
    325 
    326             iterator end() noexcept;
    327 
    328             const_iterator end() const noexcept;
     322            iterator begin() noexcept
     323            {
     324                return &data_[0];
     325            }
     326
     327            const_iterator begin() const noexcept
     328            {
     329                return &data_[0];
     330            }
     331
     332            iterator end() noexcept
     333            {
     334                return begin() + size_;
     335            }
     336
     337            const_iterator end() const noexcept
     338            {
     339                return begin() + size_;
     340            }
    329341
    330342            reverse_iterator rbegin() noexcept
     
    348360            }
    349361
    350             const_iterator cbegin() const noexcept;
    351 
    352             const_iterator cend() const noexcept;
     362            const_iterator cbegin() const noexcept
     363            {
     364                return &data_[0];
     365            }
     366
     367            const_iterator cend() const noexcept
     368            {
     369                return cbegin() + size_;
     370            }
    353371
    354372            const_reverse_iterator crbegin() const noexcept
     
    366384             */
    367385
    368             size_type size() const noexcept;
    369 
    370             size_type length() const noexcept;
    371 
    372             size_type max_size() const noexcept;
     386            size_type size() const noexcept
     387            {
     388                return size_;
     389            }
     390
     391            size_type length() const noexcept
     392            {
     393                return size_;
     394            }
     395
     396            size_type max_size() const noexcept
     397            {
     398                return allocator_traits<allocator_type>::max_size(allocator_);
     399            }
    373400
    374401            void resize(size_type n, value_type c);
     
    376403            void resize(size_type n);
    377404
    378             size_type capacity() const noexcept;
     405            size_type capacity() const noexcept
     406            {
     407                return capacity_;
     408            }
    379409
    380410            void reserve(size_type res_arg = 0);
     
    384414            void clear() noexcept;
    385415
    386             bool empty() const noexcept;
     416            bool empty() const noexcept
     417            {
     418                return size_ == 0;
     419            }
    387420
    388421            /**
     
    390423             */
    391424
    392             const_reference operator[](size_type idx) const;
    393 
    394             reference operator[](size_type idx);
    395 
    396             const_reference at(size_type idx) const;
    397 
    398             reference at(size_type idx);
    399 
    400             const_reference front() const;
    401 
    402             reference front();
    403 
    404             const_reference back() const;
    405 
    406             reference back();
     425            const_reference operator[](size_type idx) const
     426            {
     427                return data_[idx];
     428            }
     429
     430            reference operator[](size_type idx)
     431            {
     432                return data_[idx];
     433            }
     434
     435            const_reference at(size_type idx) const
     436            {
     437                // TODO: bounds checking
     438                return data_[idx];
     439            }
     440
     441            reference at(size_type idx)
     442            {
     443                // TODO: bounds checking
     444                return data_[idx];
     445            }
     446
     447            const_reference front() const
     448            {
     449                return at(0);
     450            }
     451
     452            reference front()
     453            {
     454                return at(0);
     455            }
     456
     457            const_reference back() const
     458            {
     459                return at(size_ - 1);
     460            }
     461
     462            reference back()
     463            {
     464                return at(size_ - 1);
     465            }
    407466
    408467            /**
     
    519578            void swap(basic_string& other)
    520579                noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
    521                          allocator_traits<allocator_type>::is_always_equal);
     580                         allocator_traits<allocator_type>::is_always_equal)
     581            {
     582                std::swap(data_, other.data_);
     583                std::swap(size_, other.size_);
     584                std::swap(capacity_, other.capacity_);
     585            }
    522586
    523587            /**
     
    525589             */
    526590
    527             const value_type* c_str() const noexcept;
    528 
    529             const value_type* data() const noexcept;
    530 
    531             allocator_type get_allocator() const noexcept;
     591            const value_type* c_str() const noexcept
     592            {
     593                return data_;
     594            }
     595
     596            const value_type* data() const noexcept
     597            {
     598                return data_;
     599            }
     600
     601            allocator_type get_allocator() const noexcept
     602            {
     603                return allocator_type{allocator_};
     604            }
    532605
    533606            size_type find(const basic_string& str, size_type pos = 0) const noexcept;
     
    594667            int compare(size_type pos1, size_type n1,
    595668                        const value_type* other, size_type n2) const;
     669
     670        private:
     671            value_type* data_;
     672            size_type size_;
     673            size_type capacity_;
     674            allocator_type allocator_;
    596675    };
    597676}
Note: See TracChangeset for help on using the changeset viewer.