Commit Graph

133 Commits

Author SHA1 Message Date
Paul Sokolovsky c18ef2a9dd objstr: startswith(): Accept optional "start" arg. 2014-05-15 21:33:18 +03:00
Paul Sokolovsky 70328e419a py: Implement more complete bytes comparison handling. 2014-05-15 20:58:40 +03:00
Paul Sokolovsky a47b64ae2d objstringio: Implement io.BytesIO.
Done in generalized manner, allowing any stream class to be specified as
working with bytes.
2014-05-15 07:28:19 +03:00
Paul Sokolovsky 2a27365854 objstr.c: Partial implementation of .rsplit().
sep=None is TODO.
2014-05-14 02:42:20 +03:00
Paul Sokolovsky da9f0924ef py, unix: Add copyright for modules I worked closely on. 2014-05-13 18:41:25 +03:00
Paul Sokolovsky 5ebd5f0f19 objstr: Slice indexing: support bytes properly. 2014-05-11 21:22:59 +03:00
Paul Sokolovsky bfb8819c0c objstr: Make .split() support bytes. 2014-05-11 21:17:28 +03:00
Paul Sokolovsky 5e5d69b35e objstr: Make .join() support bytes. 2014-05-11 21:13:01 +03:00
Paul Sokolovsky eea0118654 py: Give up and make mp_obj_str_get_data() deal with bytes too.
This is not fully correct re: error handling, because we should check that
that types are used consistently (only str's or only bytes), but magically
makes lot of functions support bytes.
2014-05-11 13:51:24 +03:00
Paul Sokolovsky b2d4fc06fc objstr: Make *strip() accept bytes. 2014-05-11 13:17:29 +03:00
Paul Sokolovsky 69f3eb2c96 objstr: Make .[r]partition() work with bytes. 2014-05-11 03:33:19 +03:00
Paul Sokolovsky d915a52eb6 py: Fix prefix on few sequence helpers, was incorrectly "mp_". 2014-05-10 21:36:33 +03:00
Paul Sokolovsky 6913521911 objstr: Implement .lower() and .upper(). 2014-05-10 19:49:07 +03:00
Damien George d0a5bf34f7 py: Tidy up returning NULL which should be MP_OBJ_NOT_SUPPORTED. 2014-05-10 13:55:11 +01:00
Paul Sokolovsky 7b0f9a7d9b bytes: Implement comparison and other binary operations.
Should support everything supported by strings.
2014-05-10 04:45:02 +03:00
Paul Sokolovsky b473d0ae86 py: bytes(), str(): Add NotImplementedError for kwargs.
Addresses #567.
2014-05-06 19:31:58 +03:00
Damien George 04b9147e15 Add license header to (almost) all files.
Blanket wide to all .c and .h files.  Some files originating from ST are
difficult to deal with (license wise) so it was left out of those.

Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-03 23:27:38 +01:00
Paul Sokolovsky f54bcbf099 py, unix: Make "mpconfig.h" be first included, as other headers depend on it.
Specifically, nlr.h does.
2014-05-02 17:48:40 +03:00
Paul Sokolovsky e908591baa py: Abstract no-return attribute for functions a bit. 2014-04-30 05:35:18 +03:00
Paul Sokolovsky e14d096cb7 objstr: Optimize .rstrip() by scanning string from end. 2014-04-26 06:48:31 +03:00
Paul Sokolovsky 881078403e objstr: Implement .lstrip() & .rstrip().
Share code with .strip(). TODO: optimize .rstrip().
2014-04-26 06:20:08 +03:00
Paul Sokolovsky 504e23388c objstr: Init hash in mp_obj_str_builder_start() to 0. 2014-04-19 03:21:06 +03:00
Damien George 57a4b4f178 py: Add typecode to buffer protocol.
When querying an object that supports the buffer protocol, that object
must now return a typecode (as per binary.[ch]).  This does not have to
be honoured by the caller, but can be useful for determining element
size.
2014-04-18 22:29:21 +01:00
Damien George ea8d06c39d py: Add MP_OBJ_STOP_ITERATION and make good use of it.
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL.
This helps a lot in debugging and understanding of function API.
2014-04-17 23:19:36 +01:00
Damien George 729f7b42d6 py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
mp_obj_t->subscr now does load/store/delete.
2014-04-17 22:10:53 +01:00
Damien George ee01411036 py: Add len(bytes). 2014-04-15 23:10:00 +01:00
Damien George 897fe0c0d0 py: Add builtin functions bin and oct, and some tests for them. 2014-04-15 22:03:55 +01:00
Damien George 3bb8bd899b Make USE_COMPUTED_GOTO a config option in mpconfig.h.
Disabled by default.  Enabled in unix port.
2014-04-14 21:20:30 +01:00
Paul Sokolovsky 58676fc2c7 objstr: Allow to define statically allocated str objects.
Similar to tuples, lists, dicts. Statically allocated strings don't have hash
computed.
2014-04-14 01:45:06 +03:00
Paul Sokolovsky 59e269cfec qstr, objstr: Make sure that valid hash != 0, treat 0 as "not computed".
This feature was proposed with initial hashing RFC, and is prerequisite for
seamless static str object definition.
2014-04-14 01:43:01 +03:00
Paul Sokolovsky f130ca1f60 py: Make bytes type hashable. 2014-04-13 06:45:12 +03:00
Paul Sokolovsky 73b7027b83 objstr: Add str.encode() and bytes.decode() methods.
These largely duplicate str() & bytes() constructors' functionality,
but can be used to achieve Python2 compatibility.
2014-04-13 06:45:02 +03:00
Damien George a9ddd6d9df py: Simplify and improve mp_get_index.
It has (again) a fast path for ints, and a simplified "slow" path for
everything else.

Also simplify the way str indexing is done (now matches tuple and list).
2014-04-11 10:40:38 +00:00
Paul Sokolovsky 881d9af05e objstr: Add TODO-optimize for using .join with arbitrary iterable. 2014-04-10 01:42:40 +03:00
Damien George 038fd52faa Merge branch 'str-index' of github.com:xbe/micropython into xbe-str-index 2014-04-09 20:44:37 +01:00
Damien George b5fbd0ba87 py: Add mp_obj_is_integer; make mp_get_index check for long int.
mp_obj_is_integer should be used to check if an object is of integral
type.  It returns true for bool, small int and long int.
2014-04-09 19:55:33 +01:00
Damien George a157e4caba py: str.join can now take arbitrary iterable as argument. 2014-04-09 19:17:53 +01:00
xbe 3d9a39e211 py: Implement str.[r]index() and add tests for them. 2014-04-08 11:51:41 -07:00
xbe 729be9b3c7 py: Update comment in str.replace(). 2014-04-08 11:25:32 -07:00
Paul Sokolovsky 7a70a3ae9a bytes: Support buffer protocol. 2014-04-08 19:08:34 +03:00
Andrew Scheller 12968fb6b2 Display \r and \t escape codes in string repr 2014-04-08 02:42:50 +01:00
Damien George a12a0f78b0 py: Rename pfenv_print_int to pfenv_print_mp_int, and add back former.
stmhal relies on pfenv_* to implement its printf.  Thus, it needs a
pfenv_print_int which prints a proper 32-bit integer.  With latest
change to pfenv, this function became one that took mp_obj_t, and
extracted the integer value from that object.

To fix temporarily, pfenv_print_int has been renamed to
pfenv_print_mp_int (to indicate it takes a mp_obj_t for the int), and
pfenv_print_int has been added (which takes a normal C int).  Currently,
pfenv_print_int proxies to pfenv_print_mp_int, but this means it looses
the MSB.  Need to find a way to fix this, but the only way I can think
of will duplicate lots of code.
2014-04-08 01:29:53 +01:00
Dave Hylands c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Damien George ff715429ea py: Fix str.replace for case when arg 0 or 1 is empty string. 2014-04-07 00:39:13 +01:00
Damien George deed087e2c py: str.split: handle non-default separator. 2014-04-06 11:11:15 +01:00
Damien George ea13f407a3 py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.

To address issue #420.
2014-04-05 18:32:08 +01:00
Dave Hylands f81a49e464 Allow floating point arguments with %d,i,u,o,x,X formats 2014-04-05 08:26:51 -07:00
Dave Hylands 6756a37a77 Implements most of str.modulo
The alternate form for floating point doesn't work yet.
The %(name)s form doesn't work yet.
2014-04-03 23:55:02 -07:00
Damien George cc7085c1ce Merge branch 'fix-format-int' of github.com:dhylands/micropython into dhylands-fix-format-int
Conflicts:
	py/objstr.c
2014-04-02 20:37:05 +01:00
Dave Hylands 22fe4d7344 Fix str.format to work with {:f/g/e} and ints
Also fix objstr.c to compile when floats disabled.
2014-04-02 12:10:18 -07:00