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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 */ | 1316 */ |
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 /** | |
1327 * Is this object a String whose codepoints all fit into 8 bits? | |
1328 */ | |
1329 DART_EXPORT bool Dart_IsString8(Dart_Handle object); | |
1330 | 1326 |
1331 /** | 1327 /** |
1332 * Is this object a String whose codepoints all fit into 16 bits? | 1328 * Is this object an ASCII String? |
1333 */ | 1329 */ |
1334 DART_EXPORT bool Dart_IsString16(Dart_Handle object); | 1330 DART_EXPORT bool Dart_IsAsciiString(Dart_Handle object); |
| 1331 |
1335 | 1332 |
1336 /** | 1333 /** |
1337 * Gets the length of a String. | 1334 * Gets the length of a String. |
1338 * | 1335 * |
1339 * \param str A String. | 1336 * \param str A String. |
1340 * \param length Returns the length of the String. | 1337 * \param length Returns the length of the String. |
1341 * | 1338 * |
1342 * \return A valid handle if no error occurs during the operation. | 1339 * \return A valid handle if no error occurs during the operation. |
1343 */ | 1340 */ |
1344 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); | 1341 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* length); |
1345 | 1342 |
1346 /** | 1343 /** |
1347 * Returns a String built from the provided C string | 1344 * Returns a String built from the provided C string |
| 1345 * (There is an implicit assumption that the C string passed in contains |
| 1346 * UTF-8 encoded characters and '\0' is considered as a termination |
| 1347 * character). |
1348 * | 1348 * |
1349 * \param value A C String | 1349 * \param value A C String |
1350 * | 1350 * |
1351 * \return The String object if no error occurs. Otherwise returns | 1351 * \return The String object if no error occurs. Otherwise returns |
1352 * an error handle. | 1352 * an error handle. |
1353 */ | 1353 */ |
1354 DART_EXPORT Dart_Handle Dart_NewString(const char* str); | 1354 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str); |
1355 // TODO(turnidge): Document what happens when we run out of memory | 1355 // TODO(turnidge): Document what happens when we run out of memory |
1356 // during this call. | 1356 // during this call. |
1357 | 1357 |
1358 /** | 1358 /** |
1359 * Returns a String built from an array of 8-bit codepoints. | 1359 * Returns a String built from an array of UTF-8 encoded characters. |
1360 * | 1360 * |
1361 * \param value An array of 8-bit codepoints. | 1361 * \param utf8_array An array of UTF-8 encoded characters. |
1362 * \param length The length of the codepoints array. | 1362 * \param length The length of the codepoints array. |
1363 * | 1363 * |
1364 * \return The String object if no error occurs. Otherwise returns | 1364 * \return The String object if no error occurs. Otherwise returns |
1365 * an error handle. | 1365 * an error handle. |
1366 */ | 1366 */ |
1367 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | 1367 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
1368 intptr_t length); | 1368 intptr_t length); |
1369 | 1369 |
1370 /** | 1370 /** |
1371 * Returns a String built from an array of 16-bit codepoints. | 1371 * Returns a String built from an array of UTF-16 encoded characters. |
1372 * | 1372 * |
1373 * \param value An array of 16-bit codepoints. | 1373 * \param utf16_array An array of UTF-16 encoded characters. |
1374 * \param length The length of the codepoints array. | 1374 * \param length The length of the codepoints array. |
1375 * | 1375 * |
1376 * \return The String object if no error occurs. Otherwise returns | 1376 * \return The String object if no error occurs. Otherwise returns |
1377 * an error handle. | 1377 * an error handle. |
1378 */ | 1378 */ |
1379 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | 1379 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
1380 intptr_t length); | 1380 intptr_t length); |
1381 | 1381 |
1382 /** | 1382 /** |
1383 * Returns a String built from an array of 32-bit codepoints. | 1383 * Returns a String built from an array of UTF-32 encoded characters. |
1384 * | 1384 * |
1385 * \param value An array of 32-bit codepoints. | 1385 * \param utf32_array An array of UTF-32 encoded characters. |
1386 * \param length The length of the codepoints array. | 1386 * \param length The length of the codepoints array. |
1387 * | 1387 * |
1388 * \return The String object if no error occurs. Otherwise returns | 1388 * \return The String object if no error occurs. Otherwise returns |
1389 * an error handle. | 1389 * an error handle. |
1390 */ | 1390 */ |
1391 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1391 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const uint32_t* utf32_array, |
1392 intptr_t length); | 1392 intptr_t length); |
1393 | 1393 |
1394 /** | 1394 /** |
1395 * Is this object an external String? | 1395 * Is this object an external String? |
1396 * | 1396 * |
1397 * An external String is a String which references a fixed array of | 1397 * An external String is a String which references a fixed array of |
1398 * codepoints which is external to the Dart heap. | 1398 * codepoints which is external to the Dart heap. |
1399 */ | 1399 */ |
1400 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object); | 1400 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object); |
1401 | 1401 |
1402 /** | 1402 /** |
1403 * Retrieves the peer pointer associated with an external String. | 1403 * Retrieves the peer pointer associated with an external String. |
1404 */ | 1404 */ |
1405 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1405 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
1406 void** peer); | 1406 void** peer); |
1407 | 1407 |
1408 | |
1409 /** | 1408 /** |
1410 * Returns a String which references an external array of 8-bit codepoints. | 1409 * Returns a String which references an external array of UTF-8 encoded |
| 1410 * characters. |
1411 * | 1411 * |
1412 * \param value An array of 8-bit codepoints. This array must not move. | 1412 * \param utf8_array An array of UTF-8 encoded characters. This must not move. |
1413 * \param length The length of the codepoints array. | 1413 * \param length The length of the characters array. |
1414 * \param peer An external pointer to associate with this string. | 1414 * \param peer An external pointer to associate with this string. |
1415 * \param callback A callback to be called when this string is finalized. | 1415 * \param cback A callback to be called when this string is finalized. |
1416 * | 1416 * |
1417 * \return The String object if no error occurs. Otherwise returns | 1417 * \return The String object if no error occurs. Otherwise returns |
1418 * an error handle. | 1418 * an error handle. |
1419 */ | 1419 */ |
1420 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, | 1420 DART_EXPORT Dart_Handle Dart_NewExternalUTF8String(const uint8_t* utf8_array, |
1421 intptr_t length, | 1421 intptr_t length, |
1422 void* peer, | 1422 void* peer, |
1423 Dart_PeerFinalizer callback); | 1423 Dart_PeerFinalizer cback); |
1424 | 1424 |
1425 /** | 1425 /** |
1426 * Returns a String which references an external array of 16-bit codepoints. | 1426 * Returns a String which references an external array of UTF-16 encoded |
| 1427 * characters. |
1427 * | 1428 * |
1428 * \param value An array of 16-bit codepoints. This array must not move. | 1429 * \param utf16_array An array of UTF-16 encoded characters. This must not move. |
1429 * \param length The length of the codepoints array. | 1430 * \param length The length of the characters array. |
1430 * \param peer An external pointer to associate with this string. | 1431 * \param peer An external pointer to associate with this string. |
1431 * \param callback A callback to be called when this string is finalized. | 1432 * \param cback A callback to be called when this string is finalized. |
1432 * | 1433 * |
1433 * \return The String object if no error occurs. Otherwise returns | 1434 * \return The String object if no error occurs. Otherwise returns |
1434 * an error handle. | 1435 * an error handle. |
1435 */ | 1436 */ |
1436 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, | 1437 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
1437 intptr_t length, | 1438 intptr_t length, |
1438 void* peer, | 1439 void* peer, |
1439 Dart_PeerFinalizer callback); | 1440 Dart_PeerFinalizer cback); |
1440 | 1441 |
1441 /** | 1442 /** |
1442 * Returns a String which references an external array of 32-bit codepoints. | 1443 * Gets the C string representation of a String. |
| 1444 * (It is a sequence of UTF-8 encoded values with a '\0' termination.) |
1443 * | 1445 * |
1444 * \param value An array of 32-bit codepoints. This array must not move. | 1446 * \param str A string. |
1445 * \param length The length of the codepoints array. | 1447 * \param cstr Returns the String represented as a C string. |
1446 * \param peer An external pointer to associate with this string. | 1448 * This C string is scope allocated and is only valid until |
1447 * \param callback A callback to be called when this string is finalized. | 1449 * the next call to Dart_ExitScope. |
1448 * | 1450 * |
1449 * \return The String object if no error occurs. Otherwise returns | 1451 * \return A valid handle if no error occurs during the operation. |
1450 * an error handle. | |
1451 */ | 1452 */ |
1452 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, | 1453 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, |
1453 intptr_t length, | 1454 const char** cstr); |
1454 void* peer, | |
1455 Dart_PeerFinalizer callback); | |
1456 | 1455 |
1457 /** | 1456 /** |
1458 * Gets the codepoints from a String. | 1457 * 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 * | 1458 * |
1463 * \param str A string. | 1459 * \param str A string. |
1464 * \param codepoints An array allocated by the caller, used to return | 1460 * \param utf8_array An array allocated by the caller, used to return |
1465 * the array of codepoints. | 1461 * the array of UTF-8 encoded characters. |
1466 * \param length Used to pass in the length of the provided array. | 1462 * \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. | 1463 * Used to return the length of the array which was actually used. |
1468 * | 1464 * |
1469 * \return A valid handle if no error occurs during the operation. | 1465 * \return A valid handle if no error occurs during the operation. |
1470 */ | 1466 */ |
1471 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | 1467 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, |
1472 uint8_t* codepoints, | 1468 uint8_t* utf8_array, |
1473 intptr_t* length); | 1469 intptr_t* length); |
1474 // TODO(turnidge): Rename to GetString8 to be consistent with the Is* | |
1475 // and New* functions above? | |
1476 | 1470 |
1477 /** | 1471 /** |
1478 * Gets the codepoints from a String. | 1472 * 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 * | 1473 * |
1483 * \param str A string. | 1474 * \param str A string. |
1484 * \param codepoints An array allocated by the caller, used to return | 1475 * \param utf16_array An array allocated by the caller, used to return |
1485 * the array of codepoints. | 1476 * the array of UTF-16 encoded characters. |
1486 * \param length Used to pass in the length of the provided array. | 1477 * \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. | 1478 * Used to return the length of the array which was actually used. |
1488 * | 1479 * |
1489 * \return A valid handle if no error occurs during the operation. | 1480 * \return A valid handle if no error occurs during the operation. |
1490 */ | 1481 */ |
1491 DART_EXPORT Dart_Handle Dart_StringGet16(Dart_Handle str, | 1482 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, |
1492 uint16_t* codepoints, | 1483 uint16_t* utf16_array, |
1493 intptr_t* length); | 1484 intptr_t* length); |
1494 | 1485 |
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 | 1486 |
1538 // --- Lists --- | 1487 // --- Lists --- |
1539 | 1488 |
1540 /** | 1489 /** |
1541 * Is this object a List? | 1490 * Is this object a List? |
1542 */ | 1491 */ |
1543 DART_EXPORT bool Dart_IsList(Dart_Handle object); | 1492 DART_EXPORT bool Dart_IsList(Dart_Handle object); |
1544 | 1493 |
1545 /** | 1494 /** |
1546 * Returns a List of the desired length. | 1495 * Returns a List of the desired length. |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2768 * | 2717 * |
2769 * \param object An object. | 2718 * \param object An object. |
2770 * \param peer A value to store in the peer field. | 2719 * \param peer A value to store in the peer field. |
2771 * | 2720 * |
2772 * \return Returns an error if 'object' is a subtype of Null, num, or | 2721 * \return Returns an error if 'object' is a subtype of Null, num, or |
2773 * bool. | 2722 * bool. |
2774 */ | 2723 */ |
2775 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); | 2724 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); |
2776 | 2725 |
2777 #endif // INCLUDE_DART_API_H_ | 2726 #endif // INCLUDE_DART_API_H_ |
OLD | NEW |