Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: runtime/vm/object.h

Issue 11416054: Provide a code point iterator to the String class to simplify iteration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: presubmit Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 3690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3701 3701
3702 static const intptr_t kOneByteChar = 1; 3702 static const intptr_t kOneByteChar = 1;
3703 static const intptr_t kTwoByteChar = 2; 3703 static const intptr_t kTwoByteChar = 2;
3704 3704
3705 // All strings share the same maximum element count to keep things 3705 // All strings share the same maximum element count to keep things
3706 // simple. We choose a value that will prevent integer overflow for 3706 // simple. We choose a value that will prevent integer overflow for
3707 // 2 byte strings, since it is the worst case. 3707 // 2 byte strings, since it is the worst case.
3708 static const intptr_t kSizeofRawString = sizeof(RawObject) + (2 * kWordSize); 3708 static const intptr_t kSizeofRawString = sizeof(RawObject) + (2 * kWordSize);
3709 static const intptr_t kMaxElements = kSmiMax / kTwoByteChar; 3709 static const intptr_t kMaxElements = kSmiMax / kTwoByteChar;
3710 3710
3711 class CodePointIterator : public ValueObject {
3712 public:
3713 explicit CodePointIterator(const String& str)
3714 : str_(str),
3715 index_(-1),
3716 ch_(-1) {
3717 }
3718
3719 int32_t Current() {
3720 ASSERT(index_ >= 0);
3721 ASSERT(index_ < str_.Length());
3722 return ch_;
3723 }
3724
3725 bool Next();
3726
3727 private:
3728 const String& str_;
3729 intptr_t index_;
3730 int32_t ch_;
3731 DISALLOW_IMPLICIT_CONSTRUCTORS(CodePointIterator);
3732 };
3733
3711 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } 3734 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); }
3712 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } 3735 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
3713 3736
3714 virtual intptr_t Hash() const; 3737 virtual intptr_t Hash() const;
3715 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 3738 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
3716 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 3739 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
3717 static intptr_t Hash(const uint8_t* characters, intptr_t len); 3740 static intptr_t Hash(const uint8_t* characters, intptr_t len);
3718 static intptr_t Hash(const uint16_t* characters, intptr_t len); 3741 static intptr_t Hash(const uint16_t* characters, intptr_t len);
3719 static intptr_t Hash(const uint32_t* characters, intptr_t len); 3742 static intptr_t Hash(const uint32_t* characters, intptr_t len);
3720 3743
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after
5921 if (this->CharAt(i) != str.CharAt(begin_index + i)) { 5944 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
5922 return false; 5945 return false;
5923 } 5946 }
5924 } 5947 }
5925 return true; 5948 return true;
5926 } 5949 }
5927 5950
5928 } // namespace dart 5951 } // namespace dart
5929 5952
5930 #endif // VM_OBJECT_H_ 5953 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698