OLD | NEW |
---|---|
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 INCLUDE_DART_API_H_ | 5 #ifndef INCLUDE_DART_API_H_ |
6 #define INCLUDE_DART_API_H_ | 6 #define INCLUDE_DART_API_H_ |
7 | 7 |
8 /** \mainpage Dart Embedding API Reference | 8 /** \mainpage Dart Embedding API Reference |
9 * | 9 * |
10 * Dart is a class-based programming language for creating structured | 10 * Dart is a class-based programming language for creating structured |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1317 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value); | 1317 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, double* value); |
1318 | 1318 |
1319 // --- Strings --- | 1319 // --- Strings --- |
1320 | 1320 |
1321 /** | 1321 /** |
1322 * Is this object a String? | 1322 * Is this object a String? |
1323 */ | 1323 */ |
1324 DART_EXPORT bool Dart_IsString(Dart_Handle object); | 1324 DART_EXPORT bool Dart_IsString(Dart_Handle object); |
1325 | 1325 |
1326 /** | 1326 /** |
1327 * Is this object a String whose codepoints all fit into 8 bits? | |
1328 */ | |
1329 DART_EXPORT bool Dart_IsString8(Dart_Handle object); | |
Anton Muhin
2012/10/25 13:35:48
Internally, are all the strings utf16 now?
I am a
siva
2012/10/26 21:38:29
No we still retain the one byte string representat
| |
1330 | |
1331 /** | |
1332 * Is this object a String whose codepoints all fit into 16 bits? | |
1333 */ | |
1334 DART_EXPORT bool Dart_IsString16(Dart_Handle object); | |
1335 | |
1336 /** | |
1337 * Gets the length of a String. | 1327 * Gets the length of a String. |
1338 * | 1328 * |
1339 * \param str A String. | 1329 * \param str A String. |
1340 * \param length Returns the length of the String. | 1330 * \param length Returns the length of the String. |
1341 * | 1331 * |
1342 * \return A valid handle if no error occurs during the operation. | 1332 * \return A valid handle if no error occurs during the operation. |
1343 */ | 1333 */ |
1344 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); | 1334 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); |
1345 | 1335 |
1346 /** | 1336 /** |
1347 * Returns a String built from the provided C string | 1337 * Returns a String built from the provided C string |
1338 * (There is an implicit assumption that the C string passed in contains | |
1339 * UTF-8 encoded characters and '\0' is considered as a termination | |
1340 * character). | |
1348 * | 1341 * |
1349 * \param value A C String | 1342 * \param value A C String |
1350 * | 1343 * |
1351 * \return The String object if no error occurs. Otherwise returns | 1344 * \return The String object if no error occurs. Otherwise returns |
1352 * an error handle. | 1345 * an error handle. |
1353 */ | 1346 */ |
1354 DART_EXPORT Dart_Handle Dart_NewString(const char* str); | 1347 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str); |
1355 // TODO(turnidge): Document what happens when we run out of memory | 1348 // TODO(turnidge): Document what happens when we run out of memory |
1356 // during this call. | 1349 // during this call. |
1357 | 1350 |
1358 /** | 1351 /** |
1359 * Returns a String built from an array of 8-bit codepoints. | 1352 * Returns a String built from an array of UTF-8 encoded characters. |
1360 * | 1353 * |
1361 * \param value An array of 8-bit codepoints. | 1354 * \param utf8_array An array of UTF-8 encoded characters. |
1362 * \param length The length of the codepoints array. | 1355 * \param length The length of the codepoints array. |
1363 * | 1356 * |
1364 * \return The String object if no error occurs. Otherwise returns | 1357 * \return The String object if no error occurs. Otherwise returns |
1365 * an error handle. | 1358 * an error handle. |
1366 */ | 1359 */ |
1367 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | 1360 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
1368 intptr_t length); | 1361 intptr_t length); |
1369 | 1362 |
1370 /** | 1363 /** |
1371 * Returns a String built from an array of 16-bit codepoints. | 1364 * Returns a String built from an array of UTF-16 encoded characters. |
1372 * | 1365 * |
1373 * \param value An array of 16-bit codepoints. | 1366 * \param utf16_array An array of UTF-16 encoded characters. |
1374 * \param length The length of the codepoints array. | 1367 * \param length The length of the codepoints array. |
1375 * | 1368 * |
1376 * \return The String object if no error occurs. Otherwise returns | 1369 * \return The String object if no error occurs. Otherwise returns |
1377 * an error handle. | 1370 * an error handle. |
1378 */ | 1371 */ |
1379 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | 1372 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
1380 intptr_t length); | 1373 intptr_t length); |
1381 | 1374 |
1382 /** | 1375 /** |
1383 * Returns a String built from an array of 32-bit codepoints. | 1376 * Returns a String built from an array of UTF-32 encoded characters. |
1384 * | 1377 * |
1385 * \param value An array of 32-bit codepoints. | 1378 * \param utf32_array An array of UTF-32 encoded characters. |
1386 * \param length The length of the codepoints array. | 1379 * \param length The length of the codepoints array. |
1387 * | 1380 * |
1388 * \return The String object if no error occurs. Otherwise returns | 1381 * \return The String object if no error occurs. Otherwise returns |
1389 * an error handle. | 1382 * an error handle. |
1390 */ | 1383 */ |
1391 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1384 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const uint32_t* utf32_array, |
1392 intptr_t length); | 1385 intptr_t length); |
1393 | 1386 |
1394 /** | 1387 /** |
1395 * Is this object an external String? | 1388 * Is this object an external String? |
1396 * | 1389 * |
1397 * An external String is a String which references a fixed array of | 1390 * An external String is a String which references a fixed array of |
1398 * codepoints which is external to the Dart heap. | 1391 * codepoints which is external to the Dart heap. |
1399 */ | 1392 */ |
1400 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object); | 1393 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object); |
1401 | 1394 |
1402 /** | 1395 /** |
1403 * Retrieves the peer pointer associated with an external String. | 1396 * Retrieves the peer pointer associated with an external String. |
1404 */ | 1397 */ |
1405 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1398 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
1406 void** peer); | 1399 void** peer); |
1407 | 1400 |
1408 | |
1409 /** | 1401 /** |
1410 * Returns a String which references an external array of 8-bit codepoints. | 1402 * Returns a String which references an external array of UTF-8 encoded |
1403 * characters. | |
1411 * | 1404 * |
1412 * \param value An array of 8-bit codepoints. This array must not move. | 1405 * \param utf8_array An array of UTF-8 encoded characters. This must not move. |
1413 * \param length The length of the codepoints array. | 1406 * \param length The length of the characters array. |
1414 * \param peer An external pointer to associate with this string. | 1407 * \param peer An external pointer to associate with this string. |
1415 * \param callback A callback to be called when this string is finalized. | 1408 * \param cback A callback to be called when this string is finalized. |
1416 * | 1409 * |
1417 * \return The String object if no error occurs. Otherwise returns | 1410 * \return The String object if no error occurs. Otherwise returns |
1418 * an error handle. | 1411 * an error handle. |
1419 */ | 1412 */ |
1420 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, | 1413 DART_EXPORT Dart_Handle Dart_NewExternalUTF8String(const uint8_t* utf8_array, |
1421 intptr_t length, | 1414 intptr_t length, |
1422 void* peer, | 1415 void* peer, |
1423 Dart_PeerFinalizer callback); | 1416 Dart_PeerFinalizer cback); |
1424 | 1417 |
1425 /** | 1418 /** |
1426 * Returns a String which references an external array of 16-bit codepoints. | 1419 * Returns a String which references an external array of UTF-16 encoded |
1420 * characters. | |
1427 * | 1421 * |
1428 * \param value An array of 16-bit codepoints. This array must not move. | 1422 * \param utf16_array An array of UTF-16 encoded characters. This must not move. |
1429 * \param length The length of the codepoints array. | 1423 * \param length The length of the characters array. |
1430 * \param peer An external pointer to associate with this string. | 1424 * \param peer An external pointer to associate with this string. |
1431 * \param callback A callback to be called when this string is finalized. | 1425 * \param cback A callback to be called when this string is finalized. |
1432 * | 1426 * |
1433 * \return The String object if no error occurs. Otherwise returns | 1427 * \return The String object if no error occurs. Otherwise returns |
1434 * an error handle. | 1428 * an error handle. |
1435 */ | 1429 */ |
1436 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, | 1430 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
1437 intptr_t length, | 1431 intptr_t length, |
1438 void* peer, | 1432 void* peer, |
1439 Dart_PeerFinalizer callback); | 1433 Dart_PeerFinalizer cback); |
1440 | 1434 |
1441 /** | 1435 /** |
1442 * Returns a String which references an external array of 32-bit codepoints. | 1436 * Gets the C string representation of a String. |
1437 * (It is a sequence of UTF-8 encoded values with a '\0' termination.) | |
1443 * | 1438 * |
1444 * \param value An array of 32-bit codepoints. This array must not move. | 1439 * \param str A string. |
1445 * \param length The length of the codepoints array. | 1440 * \param cstr Returns the String represented as a C string. |
1446 * \param peer An external pointer to associate with this string. | 1441 * This C string is scope allocated and is only valid until |
1447 * \param callback A callback to be called when this string is finalized. | 1442 * the next call to Dart_ExitScope. |
1448 * | 1443 * |
1449 * \return The String object if no error occurs. Otherwise returns | 1444 * \return A valid handle if no error occurs during the operation. |
1450 * an error handle. | |
1451 */ | 1445 */ |
1452 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, | 1446 DART_EXPORT Dart_Handle Dart_StringAsCString(Dart_Handle str, |
1453 intptr_t length, | 1447 const char** cstr); |
1454 void* peer, | |
1455 Dart_PeerFinalizer callback); | |
1456 | 1448 |
1457 /** | 1449 /** |
1458 * Gets the codepoints from a String. | 1450 * Gets a UTF-8 encoded representation of a String. |
1459 * | |
1460 * This function is only valid on strings for which Dart_IsString8 is | |
1461 * true. Otherwise an error occurs. | |
1462 * | 1451 * |
1463 * \param str A string. | 1452 * \param str A string. |
1464 * \param codepoints An array allocated by the caller, used to return | 1453 * \param utf8_array An array allocated by the caller, used to return |
1465 * the array of codepoints. | 1454 * the array of UTF-8 encoded characters. |
1466 * \param length Used to pass in the length of the provided array. | 1455 * \param length Used to pass in the length of the provided array. |
1467 * Used to return the length of the array which was actually used. | 1456 * Used to return the length of the array which was actually used. |
1468 * | 1457 * |
1469 * \return A valid handle if no error occurs during the operation. | 1458 * \return A valid handle if no error occurs during the operation. |
1470 */ | 1459 */ |
1471 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | 1460 DART_EXPORT Dart_Handle Dart_StringAsUTF8(Dart_Handle str, |
1472 uint8_t* codepoints, | 1461 uint8_t* utf8_array, |
1473 intptr_t* length); | 1462 intptr_t* length); |
1474 // TODO(turnidge): Rename to GetString8 to be consistent with the Is* | |
1475 // and New* functions above? | |
1476 | 1463 |
1477 /** | 1464 /** |
1478 * Gets the codepoints from a String. | 1465 * Gets the UTF-16 encoded representation of a string. |
1479 * | |
1480 * This function is only valid on strings for which Dart_IsString8 or | |
1481 * Dart_IsString16 is true. Otherwise an error occurs. | |
1482 * | 1466 * |
1483 * \param str A string. | 1467 * \param str A string. |
1484 * \param codepoints An array allocated by the caller, used to return | 1468 * \param utf16_array An array allocated by the caller, used to return |
1485 * the array of codepoints. | 1469 * the array of UTF-16 encoded characters. |
1486 * \param length Used to pass in the length of the provided array. | 1470 * \param length Used to pass in the length of the provided array. |
1487 * Used to return the length of the array which was actually used. | 1471 * Used to return the length of the array which was actually used. |
1488 * | 1472 * |
1489 * \return A valid handle if no error occurs during the operation. | 1473 * \return A valid handle if no error occurs during the operation. |
1490 */ | 1474 */ |
1491 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | 1475 DART_EXPORT Dart_Handle Dart_StringAsUTF16(Dart_Handle str, |
1492 uint16_t* codepoints, | 1476 uint16_t* utf16_array, |
1493 intptr_t* length); | 1477 intptr_t* length); |
1494 | 1478 |
1495 /** | |
1496 * Gets the codepoints from a String | |
1497 * | |
1498 * \param str A string. | |
1499 * \param codepoints An array allocated by the caller, used to return | |
1500 * the array of codepoints. | |
1501 * \param length Used to pass in the length of the provided array. | |
1502 * Used to return the length of the array which was actually used. | |
1503 * | |
1504 * \return A valid handle if no error occurs during the operation. | |
1505 */ | |
1506 DART_EXPORT Dart_Handle Dart_StringGet32(Dart_Handle str, | |
1507 uint32_t* codepoints, | |
1508 intptr_t* length); | |
1509 | |
1510 /** | |
1511 * Gets the utf8 encoded representation of a String. | |
1512 * | |
1513 * \param str A string. | |
1514 * \param utf8 Returns the String represented as a utf8 encoded C | |
1515 * string. This C string is scope allocated and is only valid until | |
1516 * the next call to Dart_ExitScope. | |
1517 * | |
1518 * \return A valid handle if no error occurs during the operation. | |
1519 */ | |
1520 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, | |
1521 const char** utf8); | |
1522 | |
1523 /** | |
1524 * Gets a UTF-8 encoded representation of a String. | |
1525 * | |
1526 * \param str A string. | |
1527 * \param bytes Returns the String represented as an array of UTF-8 | |
1528 * code units. This array is scope allocated and is only valid until | |
1529 * the next call to Dart_ExitScope. | |
1530 * \param length Returns the length of the code units array, in bytes. | |
1531 * | |
1532 * \return A valid handle if no error occurs during the operation. | |
1533 */ | |
1534 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle str, | |
1535 const uint8_t** bytes, | |
1536 intptr_t* length); | |
1537 | 1479 |
1538 // --- Lists --- | 1480 // --- Lists --- |
1539 | 1481 |
1540 /** | 1482 /** |
1541 * Is this object a List? | 1483 * Is this object a List? |
1542 */ | 1484 */ |
1543 DART_EXPORT bool Dart_IsList(Dart_Handle object); | 1485 DART_EXPORT bool Dart_IsList(Dart_Handle object); |
1544 | 1486 |
1545 /** | 1487 /** |
1546 * Returns a List of the desired length. | 1488 * Returns a List of the desired length. |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2756 * | 2698 * |
2757 * \param object An object. | 2699 * \param object An object. |
2758 * \param peer A value to store in the peer field. | 2700 * \param peer A value to store in the peer field. |
2759 * | 2701 * |
2760 * \return Returns an error if 'object' is a subtype of Null, num, or | 2702 * \return Returns an error if 'object' is a subtype of Null, num, or |
2761 * bool. | 2703 * bool. |
2762 */ | 2704 */ |
2763 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); | 2705 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); |
2764 | 2706 |
2765 #endif // INCLUDE_DART_API_H_ | 2707 #endif // INCLUDE_DART_API_H_ |
OLD | NEW |