Commit Graph

67 Commits

Author SHA1 Message Date
Dmitri Hrybenko
dc6df9307e Attempt to fix a test for NSString API on String when run on OS X 10.9
Swift SVN r21041
2014-08-05 15:05:13 +00:00
Dmitri Hrybenko
8c41e1892b stdlib/NSString APIs on String: change stringByRemovingPercentEncoding property
type to be an optional string; add tests


Swift SVN r21021
2014-08-04 18:02:14 +00:00
Dmitri Hrybenko
0e7e26328c stdlib/NSString APIs on String: add more tests
Swift SVN r21019
2014-08-04 17:01:57 +00:00
Dmitri Hrybenko
67de904c15 stdlib/NSString APIs on String: change stringByAppendingPathExtension() to
return an optional String.  This behavior is not documeted, though.


Swift SVN r21016
2014-08-04 16:41:37 +00:00
Dmitri Hrybenko
a75c7a427a stdlib/NSString APIs on String: add more tests and fix a crash in
_countFormatSpecifiers() that was triggered by non-BMP characters in the format
string


Swift SVN r21014
2014-08-04 15:37:58 +00:00
Dmitri Hrybenko
adab0726ff stdlib/NSString APIs on String: add tests for substringWithRange()
Swift SVN r21009
2014-08-04 14:49:07 +00:00
Dmitri Hrybenko
edc664c36f stdlib/NSString APIs on String: change return type of
stringByAddingPercentEncodingWithAllowedCharacters() and
stringByAddingPercentEscapesUsingEncoding() to String?, and add API notes for
NSString to the same effect


Swift SVN r21007
2014-08-04 14:13:46 +00:00
Dmitri Hrybenko
a79339ee8f stdlib/Assert: adopt new names for trapping functions:
assert() / assertionFailure() -- debug mode
precondition() / preconditionFailure() -- debug and release modes
fatalError() -- always traps


Swift SVN r20890
2014-08-01 10:22:23 +00:00
Greg Parker
3add65de36 [test] Fix un-terminated cstring in test stdlib/NSStringAPI.swift.
Swift SVN r20756
2014-07-30 14:11:24 +00:00
Dmitri Hrybenko
ac0d9b8175 stdlib/CGFloat: GYB'ify initializers that convert between CGFloat and
integer types.  Never miss an integer type again.

rdar://17853313

Swift SVN r20751
2014-07-30 11:24:11 +00:00
Dmitri Hrybenko
8db3907d54 NSStringAPI test: allow to pass under iOS simulator
Swift SVN r20704
2014-07-29 22:07:51 +00:00
Dmitri Hrybenko
3e32ff188f stdlib/String: change String.stringByAbbreviatingWithTildeInPath into a
property, to match recent Foundation headers


Swift SVN r20674
2014-07-29 16:08:39 +00:00
Dmitri Hrybenko
98188d1da9 NSString APIs on String: add more tests
Swift SVN r20673
2014-07-29 16:06:36 +00:00
Dmitri Hrybenko
ca07053adc stdlib: rename fatalError() to debugTrap()
Part of rdar://17792445


Swift SVN r20619
2014-07-28 11:14:52 +00:00
Dmitri Hrybenko
5e82e13234 stdlib: NSString APIs on String: more extensive tests for getCString() and
getFileSystemRepresentation()

rdar://17034216


Swift SVN r20617
2014-07-28 09:54:56 +00:00
Dmitri Hrybenko
b204bed0b8 stdlib: NSString APIs on String: add a test that shows getCString() behavior
when supplied a string with unpaired surrogates

rdar://17034216


Swift SVN r20616
2014-07-28 09:13:01 +00:00
Dave Abrahams
31d6f95452 [stdlib] UnsafeBufferPointer: add ".count"
In answering a forum post I noiced that I wanted this and it was
missing.

Also, extensive comments

Also, rename the length: init parameter to count:.  When writing the
comments for the init function it became painfully clear why we use
"count" is better than "length" especially around pointers and memory:
the former is much less easy to mistake for "length in bytes".  Plus
it's consistent with the new ".count" property

Swift SVN r20609
2014-07-28 01:03:09 +00:00
Dmitri Hrybenko
06a9ea552c stdlib/String: fix hasPrefix() and hasSuffix() to perform proper Unicode
comparison

rdar://17498444


Swift SVN r20603
2014-07-27 18:12:02 +00:00
Dave Abrahams
b81c4b2dca Revert "[stdlib] Concise operators for advance(i, +/-n)"
This reverts r20561 until we've had a chance to discuss it in a design meeting

Swift SVN r20579
2014-07-25 23:52:38 +00:00
Dave Abrahams
b2ac0e32dd [stdlib] Concise operators for advance(i, +/-n)
Fixes <rdar://problem/17814560>.

Swift SVN r20561
2014-07-25 20:53:38 +00:00
Dmitri Hrybenko
ed855afb68 stdlib/String: use the Unicode collation algorithm in String's and Character's conformance to Comparable
rdar://17498444


Swift SVN r20554
2014-07-25 18:32:36 +00:00
Dmitri Hrybenko
c44b42c7aa stdlib/String: add a test that shows that equality comparison of strings
is performed according to the deterministic Unicode collation algorithm,
which allows us to use the hash of the NFD form.

rdar://17498444

Swift SVN r20543
2014-07-25 14:31:07 +00:00
Dmitri Hrybenko
a38b282a7b StdlibUnittest: move checkHashable to unit testing library, it is a
utility that is useful in general

Swift SVN r20536
2014-07-25 10:06:22 +00:00
Dmitri Hrybenko
aa929798d0 stdlib: eliminate an inconsistent overload of == on NSString that would
make == and != inconsistent in non-generic code, and that would not be
used at all in generic code.

Part of rdar://17498444

Swift SVN r20524
2014-07-24 22:38:41 +00:00
Dmitri Hrybenko
27cbb5a9d5 stdlib/String: change == to perform string comparison after NFD
normalization

There is still some obscure bug with != on NSString, probably caused by
an ill-thought overload somewhere.

Part of rdar://17498444

Swift SVN r20518
2014-07-24 21:36:01 +00:00
Dmitri Hrybenko
c2adafc897 Revert "stdlib/String: change == to perform string comparison after NFD"
This breaks consistency between == comparison and hash value.

Swift SVN r20500
2014-07-24 17:28:40 +00:00
Dmitri Hrybenko
a3d5a8a0de stdlib/String: change == to perform string comparison after NFD
normalization

There is still some obscure bug with != on NSString, probably caused by
an ill-thought overload somewhere.

Part of rdar://17498444

Swift SVN r20495
2014-07-24 16:51:48 +00:00
Dave Abrahams
1a7648b04b [stdlib] String.stringWithBytes: drop length param
The length could already be given by the input sequence.  Also, make it
accept any generic Sequence of bytes, rather than requiring an array.

Fixes <rdar://problem/17034413>

Swift SVN r20480
2014-07-24 08:23:10 +00:00
Dave Abrahams
993c7e0bae [stdlib] Replace .toSigned()/.toUnsigned() methods
...because their semantics were unclear.  The new idiom is explicit
construction of the target type using the "bitPattern:" argument label:

    myInt.toUnsigned() => UInt(bitPattern: myInt)

Fixes <rdar://problem/17000821>

Swift SVN r20479
2014-07-24 08:07:07 +00:00
Dave Abrahams
e3f8d0e630 [stdlib] rename UnsafeArray => UnsafeBufferPointer
Also,

  UnsafeMutableArray => UnsafeMutableBufferPointer
  withUnsafeMutableStorage => withUnsafeMutableBufferPointer

Swift SVN r20340
2014-07-22 22:20:37 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Dave Abrahams
079b5e57ef [stdlib] += no longer appends array elements
+= only extends arrays with another sequence of the same element type.

Fixes <rdar://problem/17151420> The use of the overloaded += operator in
Swift is inconsistent and confusing with Arrays.

Note that this commits generated 3 new radars against the type checker:

  <rdar://problem/17751308>
  <rdar://problem/17750582>
  <rdar://problem/17751359>

Swift SVN r20274
2014-07-21 20:07:13 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Dmitri Hrybenko
09bbec7464 stdlib: fix a crash in String.rangeOfString when the result is NSNotFound
rdar://17550857


Swift SVN r19611
2014-07-07 15:25:10 +00:00
Dmitri Hrybenko
3422201d21 stdlib/String: move lowercaseString and uppercaseString properties to
Foundation, and have them forward to Foundation.

This is slower than it could be, but at least this way we produce correct
results.

Another part of rdar://17550187


Swift SVN r19560
2014-07-04 09:27:32 +00:00
Joe Groff
c34b4f6a9e Enable string-to-pointer conversions and remove CString.
There is some follow-up work remaining:

- test/stdlib/UnicodeTrie test kills the type checker without manual type annotations. <rdar://problem/17539704>
- test/Sema/availability test raises a type error on 'a: String == nil', which we want, but probably not as a side effect of string-to-pointer conversions. I'll fix this next.

Swift SVN r19477
2014-07-02 19:15:10 +00:00
Dmitri Hrybenko
f3c7bdc273 stdlib/NSString APIs on String: change substringFromIndex() and
substringToIndex() to accept String.Index instead of Int

rdar://17306557


Swift SVN r19467
2014-07-02 15:58:59 +00:00
Dmitri Hrybenko
7e4c6782ee stdlib/String: rename String.utf16count -> .utf16Count to follow naming
conventions

rdar://17016806


Swift SVN r19463
2014-07-02 15:03:02 +00:00
Chris Lattner
287059b360 implement <rdar://problem/17279286> Swift has too many Unicode escape sequence forms
This consolidates the \x, \u, and \U escape sequences into one \u{abc} escape sequence.
For now we still parse and cleanly reject the old forms with a nice error message, this
will eventually be removed in a later beta (tracked by rdar://17527814)


Swift SVN r19435
2014-07-01 23:27:44 +00:00
Dmitri Hrybenko
4814e00fda stdlib/String: implement Unicode extended grapheme cluster segmentation
algorithm

The implementation uses a specialized trie that has not been tuned to the table
data.  I tried guessing parameter values that should work well, but did not do
any performance measurements.

There is no efficient way to initialize arrays with static data in Swift.  The
required tables are being generated as C++ code in the runtime library.

rdar://16013860


Swift SVN r19340
2014-06-30 14:38:53 +00:00
Dave Abrahams
ab322aead3 [stdlib] Introduce/use a free array-yeilding map()
Some of the lazy() instances in the previous commit that were being
immediately array'd are now even simpler.

Swift SVN r19313
2014-06-28 00:35:43 +00:00
Dave Abrahams
a7f6b97222 [stdlib] Introduce lazy() and use it for mapping
Swift SVN r19312
2014-06-28 00:35:43 +00:00
Doug Gregor
e064416c8f Update the rest of the testsuite for the array syntax change.
Swift SVN r19223
2014-06-26 05:39:25 +00:00
Ted Kremenek
58558fcca3 Rename 'succ' and 'pred' to 'successor' and 'predecessor' respectively.
This is motivated by <rdar://problem/17051606>.

This ends up renaming variables as well, which seems right for
consistency since we use "predicate" as variable name.

Swift SVN r19135
2014-06-24 19:27:19 +00:00
Dmitri Hrybenko
f370ca0746 stdlib: fix a bunch of various Unicode issues, primarily in UTF-8 decoding
In UTF-8 decoder:
- implement U+FFFD insertion according to the recommendation given in the
  Unicode spec.  This required changing the decoder to become stateful, which
  significantly increased complexity due to the need to maintain an internal
  buffer.
- reject invalid code unit sequences properly instead of crashing rdar://16767868
- reject overlong sequences rdar://16767911

In stdlib:
- change APIs that assume that UTF decoding can never fail to account for
  possibility of errors
- fix a bug in UnicodeScalarView that could cause a crash during backward
  iteration if U+8000 is present in the string
- allow noncharacters in UnicodeScalar.  They are explicitly allowed in the
  definition of "Unicode scalar" in the specification.  Disallowing noncharacters
  in UnicodeScalar prevents actually using these scalar values as internal
  special values during string processing, which is exactly the reason why they
  are reserved in the first place.
- fix a crash in String.fromCString() that could happen if it was passed a null
  pointer

In Lexer:
- allow noncharacters in string literals.  These Unicode scalar values are not
  allowed to be exchanged externally, but it is totally reasonable to have them
  in literals as long as they don't escape the program.  For example, using
  U+FFFF as a delimiter and then calling str.split("\uffff") is completely
  reasonable.

This is a lot of changes in a single commit; the primary reason why they are
lumped together is the need to change stdlib APIs to account for the
possibility of UTF decoding failure, and this has long-reaching effects
throughout stdlib where these APIs are used.


Swift SVN r19045
2014-06-20 13:07:40 +00:00
Chris Lattner
70076cf958 switch the testsuite to use the ..< operator instead of ..
Swift SVN r19003
2014-06-19 17:18:23 +00:00
Dmitri Hrybenko
4904685f8f Extract some unit testing helpers from NSStringAPI into a module
Swift SVN r18956
2014-06-17 16:25:37 +00:00
Dmitri Hrybenko
5649360b8f stdlib/NSString APIs on String: add more tests
Swift SVN r18682
2014-05-30 23:49:22 +00:00
Dmitri Hrybenko
a69e341aa2 stdlib/NSString APIs on String: fix a bug and add tests for
rangeOfCharacterFromSet(_:options:range:)

The underlying Objective-C API could return an NSRange of NSNotFound.  Swift's
String.Index can not represent that, so change the API to return an optional
Swift Range<Index> instead.


Swift SVN r18679
2014-05-30 23:07:21 +00:00